How can I increase the value stored in count by one every time it is a multiple of 2
I have a function that returns the value of i, it is initialized to 0 and it is auto-incrementing, that is, when i is a multiple of 2, the counter has to increases by 1
I try to do is that when i is a multiple of 2, the variable count has to increase in 1
This is the code I’m doing, could you tell me where my error is?
let count = 0;
if( i % 2 == 0){
count++;
console.log(count);
}else{
}
2
Answers
You should divide
count
by 2, noti
By the way, your code only runs once. So it seems that your code lacks some sort of a loop. There needs to be a
for
orwhile
loop.Update:
based on your comments, I think your code should look like this:
Maybe the full script like this. it works fine