Spooky Kasper would like an Assessment for the Loops 3 skill test. Thanks!

Hello,

Thanks for reading me.
I would like an Assessment for the loops 3 skill test.
It looks like my code meet the request of the test but I guess there was an easier way.

The Task was:

In this final task, you are provided with the following:

  • i — starts off with a value of 500; intended to be used as an iterator.
  • para — contains a reference to a paragraph, which will be used to report the results.
  • isPrime() — a function that, when passed a number, returns true if the number is a prime number, and false if not.

You need to use a loop to go through the numbers 2 to 500 backwards (1 is not counted as a prime number), and run the provided isPrime() function on them. For each number that isn’t a prime number, continue on to the next loop iteration. For each one that is a prime number, add it to the paragraph’s textContent along with some kind of separator.

And Here is my code:
https://codepen.io/spookykasper/pen/OJzqRGL

To meet the request of the task i create:
const separator = document.createTextNode(*);

and add it separately, but it looks like a cheat to me and I wonder
if this is actually the best practice ?

Many thanks!

Spooky

Hi @Spooky and welcome to the community :wave:

Well done!
Instead of using two createTextNode() , an easier way would be to append every number (and separator) to para with textContent :

para.textContent += `${i} * `;

You could also add a condition to not add the separator after the last number.

I hope that helps. Feel free to ask questions. :slightly_smiling_face:

Have a nice day,
Michael

1 Like

Hi @mikoMK,

Your response both answer my question and made me feel welcome,
that’s what I was hoping for :slight_smile:

Thanks!
Spooky

1 Like

I’m glad I could help.
If you like to do more exercises, we’ll be here to help. :smiley:

Michael

PS: Your email address is visible in your post. I think it somehow ended up in the optional “name” field of your profile. I recommend removing it.

1 Like