// Dodge the cannons and collect 8 gems.
// Watch out, cannons are ready to fire!
// Move slow along a special pattern to confuse them.
// This function returns a value from 0 to 30:
function mod30(n) {
if (n >= 30) {
return n - 30;
} else {
return n;
}
}
// This function should return a value from 0 to 40:
function mod40(n) {
// Use an if-statement to return the correct value.
if (n >= 40) {
n = n- 40;
return n;
} else {
return n;
}
}
// You don't need to change the following code:
while (true) {
var time = hero.now();
var x = mod30(time) + 25;
var y = mod40(time) + 10;
hero.moveXY(x, y);
}
Mod edit: Please do not request solutions. The purpose of this board is to assist people with their code. Simply providing solutions is counter productive to the learning process. There are many people here willing and able to assist you with your code but we do not just give the answers. Thanks.
# Dodge the cannons and collect 8 gems.
# Watch out, cannons are ready to fire!
# Move slow along a special pattern to confuse them.
# This function returns a value from 0 to 30 (0 <= n < 30)
def mod30(n):
if n >= 30:
return n - 30
else:
return n
# This function should return a value from 0 to 40 (0 <= n < 40)
def mod40(n):
# Use an if-statement to return the correct value.
if n:
return n
# You don't need to change the following code:
while True:
time = hero.time
x = mod30(time) + 25
y = mod40(time) + 10
hero.moveXY(25, 10)
Compare your mod40(n): function with the mod30(n): function directly above it. Your mod40 function should be exactly like the mod30(n): function but with a value of 40 instead of 30.
# Dodge the cannons and collect 8 gems.
# Watch out, cannons are ready to fire!
# Move slow along a special pattern to confuse them.
# This function returns a value from 0 to 30 (0 <= n < 30)
def mod30(n):
if n >= 30:
return n - 30
else:
return n
# This function should return a value from 0 to 40 (0 <= n < 40)
def mod40(n):
# Use an if-statement to return the correct value.
if n >= 30:
return n - 40
else:
return n
# You don't need to change the following code:
while True:
time = hero.time
x = mod30(time) + 25
y = mod40(time) + 10
hero.moveXY(25, 10)
I think I should change the if n >= 30: to if n >= 40:. So the whole code is:
def mod30(n):
if n >= 30:
return n - 30
else:
return n
# This function should return a value from 0 to 40 (0 <= n < 40)
def mod40(n):
# Use an if-statement to return the correct value.
if n >= 40:
return n - 40
else:
return n
# You don't need to change the following code:
while True:
time = hero.time
x = mod30(time) + 25
y = mod40(time) + 10
hero.moveXY(25, 10)