Home HTML Data Types DOM JavaScript JS Debugging

Scenario

The following scenario utilizes the comparison of the a & b variables, as instructed by the hack to create a intutive system in which values are assigned to the mysteryBox variable based on the randomly chosen numbers for a & b. The values for mysteryBox can either be Invincibility, x2 speed, or 1.5x Jump Power. This can be implemented in our game which is a simple platformer parkour/speedrun game in which users based off rng can get certain abilities

%%js

// Randomly Select value for a & b between 1-10
a = Math.floor(Math.random() * 11);
b = Math.floor(Math.random() * 11);

// Define Coins Variable
let mysteryBox = "empty"

// If A equals B, give User 100 coins
if (a === b) {
    mysteryBox = "Invincibility"
} 
// If A is greater than B, give User 25 coins
else if (a > b) {
    mysteryBox = "1.5x Jump Power"
} 

//If B is greater than A, give User 50 coins
else if (b > a) {
    mysteryBox = "x2 Speed"
}

// Print Current Amount of Coins
console.log("You have " + mysteryBox + " for 30 seconds!")
<IPython.core.display.Javascript object>