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 (284) [earned 5 cycles]
View Answer
heyitsmarcus (284)

@Vandesm14 With that being said, you could use hoisting in ECMAScript 5, and use your approach (change let to var). By changing from let to var the i variable is hoisted into the function scope and is then available to return and console.log.

function exerciseTwo(){
    // 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(var i = 0; i < 10; i++) {}
    //Please write your answer in the line above.

    // return i; // This will end the function right then and there, so I will rewrite it:
    console.log(i);
}