Ask coding questions

← Back to all posts
Help

I'm doing an assignment 5 For Loops an I am stuck on the second question

This is what I wrote
function exerciseTwo()
{
let count = 0;
// In this exercise write your own for loop (you can look at the syntax above).
// It should loop 10 times.
// You are given a variable called: count .
// For each loop reassign count to the current value of count + 1 .
for( let count = 0; count < 10; count++)
{
console.log(count)
}

//Please write your answer in the line above.
return count;
}

Commentshotnewtop
Coder100 (754)

Ok, so here is the problem, your loop stops at 9 because 9 < 10 and 10 is not less than 10. It is equal to 10. So what you should do instead is write:

``````for(let count = 0; count < 11; count++){
console.log(count);
}``````

So now, 10 fits the criteria, since 10 is < 11.
Hopes this helps!

cccpfsb (0)

@Coder100 I tried this it still gives me an Error

Coder100 (754)

Ok, maybe you should do

``````for(let count = 0; count <= 10; count++){
console.log(count);
}``````

So it fits the criteria still?
@cccpfsb