3/7 for loops. Evaluation error?


#1

I think there is an error in the way my code is evaluated in this particular exercise. It seems to only be evaluating a specific variable as “correct”

<Below this line, add a link to the EXACT exercise that you are stuck at.>

https://www.codecademy.com/courses/learn-javascript/lessons/loops/exercises/for-loop?action=lesson_resume

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

When writing my for loop I used a different variable than the example just because I wasn’t using the example as a prompt for the variable because…, well it should be able to vary as long as it’s consistent. Right?
In the for loop I used: var vacay = 0;
and received error message
Did you write the conditions in the for loop’s parentheses like the example?

The output is fine/correct but it wouldn’t allow me to advance until I used the “correct variable” which in this case was: var i = 0;

Same output
I found this odd so I reset the exercise, rewrote my code and this time tried using a single letter variable: var p = 0;
I received the same message:

Did you write the conditions in the for loop’s parentheses like the example?

And again the output was fine but I wasn’t getting the check mark allowing me to advance.

```

var vacationSpots = [‘Scotland’, ‘Ireland’, ‘Australia’];

for (var vacay = 0; vacay < vacationSpots.length; vacay++) {
console.log(vacationSpots[vacay]);
}

Did you write the conditions in the for loop’s parentheses like the example?

SO I THEN TRIED

var vacationSpots = [‘Scotland’, ‘Ireland’, ‘Australia’];

for (var p = 0; p < vacationSpots.length; p++) {
console.log(vacationSpots[p]);
}

Did you write the conditions in the for loop’s parentheses like the example?

“CORRECT CODE”

var vacationSpots = [‘Scotland’, ‘Ireland’, ‘Australia’];

for (var i = 0; i < vacationSpots.length; i++) {
console.log(vacationSpots[i]);
}

<do not remove the three backticks above>

#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.