#716. Counting multiples
When the green flag is clicked, this script runs. What is the value of the **c** variable?
when green flag clicked set [i v] to (0) set [c v] to (0) repeat (36) change [i v] by (1) if <((i) mod (4)) = (0)> then change [c v] by (1) end end
# When the green flag is clicked
i = 0
c = 0
for _ in range(36):
i += 1
if (i % 4) == 0:
c += 1
// Scratch's mod gives a positive remainder even for negative numbers
function mod(a, b) {
return ((a % b) + b) % b;
}
let i = 0, c = 0;
// When the green flag is clicked
i = 0;
c = 0;
for (let j = 0; j < 36; j++) {
i += 1;
if ((mod(i, 4)) === 0) {
c += 1;
}
}
💡 Not sure? Build it in Scratch and try it out.