//hi guys, wrapping my head around an exercise from the Eloquent Javascript book
//can anyone analyse this please?
let char1 = “#”;
for (let counter = 0; counter < 6; counter + 1) {
console.log(char1);
char = char + “#”;
}
//hi guys, wrapping my head around an exercise from the Eloquent Javascript book
//can anyone analyse this please?
let char1 = “#”;
for (let counter = 0; counter < 6; counter + 1) {
console.log(char1);
char = char + “#”;
}
I understand your feeling.
This part is wrong:
counter + 1
This simply means “the value” of counter+1
but it is not storing to anything.
If you want to increase counter
by one, you do like this:
counter = counter + 1
counter += 1
counter++
All three have the same effect. The first one is adding counter
by 1
and then it is storing that value to the same counter
. The second one and third one is incrementing itself (counter
) by 1.
You were experiencing infinite loop because the counter
was never increasing.