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?
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.
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?