

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 10
click for more info
Not enough gems
Cost: 6 gems
1: Loops
incomplete
2: Break
incomplete
3: Continue
incomplete
4: While
incomplete
5: For...in
incomplete
This lesson's interactive features are locked, please to keep using them
The continue keyword stops the current iteration of a loop and immediately moves on to the next one.
for (let i = 0; i < 10; i++) {
if (i % 2 === 0) {
continue;
}
console.log(i);
}
// Prints:
// 1
// 3
// 5
// 7
// 9
...I'm gonna break the 4th wall and not even pretend this assignment has anything to do with "Textio". The prime-checking logic is mapped out below. Focus on using continue and break in the right spots.
Complete the printPrimes function. It should print all of the prime numbers up to and including max. It should skip any numbers that are not prime.
Use this checklist:
for n from 2 to max (inclusive):
if n is 2:
n is prime, print it
if n is even:
n is not prime, skip to next n
for i from 3 to the square root of n (inclusive) in steps of 2:
if n can be evenly divided by i:
n is not prime, stop checking factors
n is prime, print it
n. A factor higher than the square root of n must multiply with a factor lower than the square root of n, meaning it has no chance of multiplying evenly into n.
i * i <= nThis lesson is graded based on the output of your program, so don't leave any debugging print statements in your code.
The primes up to 10 are:
2
3
5
7
Only print the numbers themselves, no headings or delimiters.
Use continue when n is 2, and again when n is even. For the inner loop, use break to stop checking factors early. Then only print the number after the inner loop if you never found a factor.