3
JS Assignment 5: For Loops
JerehlDyer (2)

What am I doing wrong here?

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++)
//Please write your answer in the line above.
return count;
}

You are viewing a single comment. View All
Answered by heyitsmarcus (280) [earned 5 cycles]
View Answer
1
kurrycat2004 (0)

I think its because of that return count;.
Return returns in your case the var count but it exits also the function. So the for loop would only run one time and then cause of that return it will exit.

1
heyitsmarcus (280)

@kurrycat2004 That is one of the problems. Since it's the next line of execution (and there are no curly braces), it is running inside the for loop and immediately returns once the first loop is entered into. But, there's also the problem of let count = 0 inside the for loop. You can see my answer for a more detailed explanation of what all is happening inside this function.