Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Don't Rush Be Quiet (Javascript)

I’m not sure what’s happening, but Tharin just stops due to an error on the last gem. It says that x and y in line 28 are not defined. Here is my code. It says I don’t need to change the code at all…

// 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)
function mod30(n) {
    if (n > 30) {
        return n - 30;
    } else {
        return n;
    }
}

// This function should return a value from 0 to 40 (0 <= n < 40)
function mod40(n) {
    // Use an if-statement to return the correct value.
    if (n < 40) {
        return n; 
    }
   
}

// You don't need to change the following code:
while (true) {
    var time = hero.time;
    var x = mod30(time) + 25;
    var y = mod40(time) + 10;
    hero.moveXY(x, y);
}

1 Like

Hello, welcome to the Forum.

The easiest thing I can say is take a closer look at the mod30 function above and mimic that code only changing the number.

1 Like
function mod40(n) {
    // Use an if-statement to return the correct value.
    if (n < 40) {
        return n; 
    }  
}

I think the error is that mod40(n) is not defined when n > 40. It also may help to read brooksy’s post.

2 Likes