Debugging: Catch OBOE Question

Please see link below:

I completed the challenge using two different types of conditions: i < len and i <= len - 1 when i = 0(initialization). However; the final checkmark item down states, “Your code should fix the terminal condition of the loop so that it stops at 1 before the length.”
I reasearched MDN docs and read through the “for” and “looping for” articles and I am still not certain what this exactly means?
Would please elaborate more?

Can you please provide your actual code? Thanks


is console.log(firstFive[i]); going to be valid when i === firstFive.length?

Please see code below.
function countToFive() {
let firstFive = “12345”;
let len = firstFive.length;
// Only change code below this line
for (let i = 0; i < len; i++) {
// Only change code above this line
console.log(firstFive[i]);
}
}

countToFive();

Also,
I tried the following code and it passed.
function countToFive() {
let firstFive = “12345”;
let len = firstFive.length;
// Only change code below this line
for (let i = 0; i <= len - 1; i++) {
// Only change code above this line
console.log(firstFive[i]);
}
}

countToFive();

My question is in the checkmark section. What does “Your code should fix the terminal condition of the loop so that it stops at 1 before the length” mean? I am not sure of how to visualize this criterion.

I’m not sure what you mean by ‘visualize’? There are only 5 elements in the array and counting starts at 0, so you have to stop at 4

So, when read "Your code should fix the terminal condition of the loop so that it stops at 1 before the length” this refers to 4. Does this sound correct to you?

Right. The last value of i while the loop body runs is 4