Let's roll two dice, add them up, and check for doubles. Run this several times. You'll get different results each time!
const die1 = Math.floor(Math.random() * 6) + 1;
const die2 = Math.floor(Math.random() * 6) + 1;
const total = die1 + die2;
const isDoubles = die1 === die2;
const isEven = total % 2 === 0;
console.log(`🎲 You rolled a ${die1} and a ${die2}`);
console.log(`Total: ${total}`);
console.log(`Doubles? ${isDoubles}`);
console.log(`Even total? ${isEven}`);
console.log(`Lucky seven? ${total === 7}`);
Output
🎲 You rolled a 4 and a 4 Total: 8 Doubles? true Even total? true Lucky seven? false
Try it yourself
Change the dice roller to roll three dice. Then add a line that prints whether the total is greater than 10. Bonus: make one of the dice a 20-sided die (the kind used in board games).
That's Grade 3 in the books! Your programs can now calculate, compare and combine. But they still can't decide anything. That changes in Grade 4, when your code learns to make choices.