+ 1
how to fix this error: In the for loop, one of the three conditions is incorrect and will cause the code to execute forever. Cha
let thingsToDo = ['do laundry', 'take out the garbage', 'make dinner', 'walk the dog', 'go to the bank']; for (let thingsToDoIndex = thingsToDo.length - 1; thingsToDoIndex >= 0; thingsToDoIndex++) { console.log('I need to ' + thingsToDo[thingsToDoIndex] + '.'); }
3 Respuestas
+ 14
replace thingsToDoIndex++ with thingsToDoIndex--
+ 1
Because you start at thingsToDo.length -1 (positive nunber), as long as thingsToDoIndex >=0 and you use ++, it will never get to 0.
p.s.
You can also start at 0, and try to reach thingsToDo.length -1.
- 1
Question: why go backwards instead of forwards?