Help with 'Loop 3'

Hi guys, I need help with the correct code to the below task. My code is in between the ‘Add code here’ and ‘Do not edit code below’ in

Hi @Anthony_Izekor,

I am happy to help you out, but your message seems to have been cut off. Can you try posting it again? Discourse sometimes does weird things when you try to post for example HTML elements and other code fragments — it will often render them rather than showing the source code. Check in the preview box to see if it is coming out the way you expected it to.

Thanks man, I have been able to resolve it.

Hello Anthony, I too had issues coming with lines of codes that could solve the challenge. Please help me out if you have found out how to solve the challenge.

Hi Ikeh, I did this:

do {

    if (isPrime(i)) {

        para.textContent += i + ' ,';

    } 

    i--;

} while (i >= 2);

Hello.

I’ve completed Loop 3 with the solution above, only with a ‘-’ separator instead. I’d like the final result to look a bit cleaner, with a ‘.’ separator for the last character (like we did with cats active learning example). I’ve tried adding an if else statement within the loop code block but keep getting stuck in an infinite loop. I’ve also tried .replace() which I can get to work in the console after running the loop, but not within the JS code block itself. What would be the best way to achieve what I want when using the do while loop as it the above post?

Many thanks

Richard

@richardanlezarklee have you got your code available online anyway, e.g. in a codepen, or could you just paste it here for me to look at?

Hello everyone, this is how i solved the task with for() loop:

for (i = 500; i >= isPrime(i); i–) {

if (isPrime(i)) {

para.textContent += i + " ";

} else {

continue;

}

}

1 Like