var tops = 5;
while (tops > 0) {
for (var spins = 0; spins < 3; spins++) {
alert("Top is spinning!");
}
tops = tops - 1;
}
Doesn’t the var = spins loops 2 times each time the var = tops decreases by one until it gets to the value of 1? Wouldn’t that code alert 8 times? I don’t know why I get the alert 16 times.
You should get the alert 15 times, not 8 or 16.
The values of
topsare 5, 4, 3, 2, 1. For each of these values,spinswill be set to 0, 1 and 2.5 (values for tops) X 3 (values for spins) = 15