Escape Room 3.15 - Hack
Extended Javascript challenges and hacks for CSP 3.15 Escape Room - Random Values
🚀 Escape Room Javascript Hacks
- Simulate drawing two random cards, where each card has a value between 1 and 10. Show the two card values and their total.
// 🎴 Simulate drawing two random cards between 1 and 10
// TODO: Generate a random value between 1 and 10 for the first card
let card1 = /* your code here */;
// TODO: Generate a random value between 1 and 10 for the second card
let card2 = /* your code here */;
// TODO: Add the two card values together
let total = /* your code here */;
// TODO: Print out the results
console.log("Card 1:", /* your code here */);
console.log("Card 2:", /* your code here */);
console.log("Total:", /* your code here */);
- Create a decision maker where “Definitely” appears 30% of the time
// 🎲 Decision Maker
// Goal: "Definitely" should appear about 30% of the time when you run this code
// TODO: Generate a random number between 1 and 100
let rand = /* your code here */;
// TODO: Use an if statement to make "Definitely" appear 30% of the time
if (/* your condition here */) {
console.log("Definitely");
} else {
console.log("Not this time");
}
- Simulate one coin flip and one dice roll.
-
The coin flip should be 0 = Heads or 1 = Tails.
-
The dice roll should be a number between 1 and 6.
-
Print out both results.
// 🪙 Simulate one coin flip and one dice roll
// TODO: Generate a random value 0 or 1 for the coin
let coin = /* your code here */;
// TODO: Print out the coin flip result
console.log("Coin flip:", /* your code here */);
// TODO: Generate a random value between 1 and 6 for the dice
let dice = /* your code here */;
// TODO: Print out the dice roll result
console.log("Dice roll:", /* your code here */);
- Write code that randomly picks one fortune from a list of 5 possible fortunes and prints it out.
// 🔮 Random Fortune Generator
// TODO: Make a list (array) of fortunes
let fortunes = [/* your 5 fortunes here */];
// TODO: Pick a random index
let index = /* your code here */;
// TODO: Print out the fortune at that index
console.log("Your fortune:", fortunes[index]);