Assessment wanted for Loops 1, 2, and 3 skill test

Hi all!

Can someone please take a look at my solutions for loop exercises in the respective section on mdn?
Did I miss anything? Anything I should improve?
Here are the codepens:
Loop 1 exercise: https://codepen.io/fantazzista/pen/dyZVBzp
Loop 2 exercise: https://codepen.io/fantazzista/pen/xxPXoWw
Loop 3 exercise: https://codepen.io/fantazzista/pen/MWOEMVR

Thanks in advance for your time.

Hi @superpav and welcome to the community :wave:

You did great :medal_sports:

Here are my comments:
Task 1: Correct :white_check_mark: You could just use = instead of += since you are redefining bulletpoint at the start of every loop.
Task 2: Correct :white_check_mark:
Task 3: Correct :white_check_mark: Simplification: You can delete the first half of your loop. This is enough:

if (isPrime(i)) {
  para.textContent += `${i} `
}

Keep up the good work and have a nice day :slightly_smiling_face:
Michael

2 Likes

Thank you Michael.
As for the 3rd task, I guess I took the line ā€˜for each number that isnā€™t a prime number, continue on to the next loop iterationā€™ too literally :smile:

Take care!

1 Like

For those interested, I think I found another way of writing the third loop. Because the line ā€œFor each number that isnā€™t a prime number, continue on to the next loop iterationā€ kind of implies that you need to use ā€˜continueā€™ in the loop. I guess continue is potentially useful if we want to decrease nesting in a loop. The result remains the same as in previous solutions, but the logic is a little bit different.

for (let i = 500; i >= 2; i--) {
      if (!isPrime(i)) continue;
      para.textContent += `${i} `;
    }
1 Like