Two Dice
Add the rolls.
Two Dice is a free Javascript for Kids lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Javascript for Kids learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Double the Fun! 🎲🎲
One die is fun, but two dice are even better! 🎲🎲
Many games roll two dice and add them together. Let's do that! ➕
console.log('Rolling two dice! 🎲🎲')
console.log('Then we add them up! ➕')Roll the First Die 🎲
First, roll one die and save it in a box called die1. 📦
Same as before: random times 6, plus 1! 🎲
let die1 = Math.floor(Math.random() * 6) + 1
console.log('Die 1: ' + die1 + ' 🎲')Roll the Second Die 🎲
Now roll a second die and save it in die2. 📦
Two separate rolls, two separate boxes! 🎲🎲
let die1 = Math.floor(Math.random() * 6) + 1
let die2 = Math.floor(Math.random() * 6) + 1
console.log('Die 1: ' + die1 + ', Die 2: ' + die2 + ' 🎲🎲')Add Them Up! ➕
Now the fun part: add the two rolls together! ➕
If you roll 3 and 4, the total is 7! 🎉
let die1 = 3
let die2 = 4
let total = die1 + die2
console.log('Total: ' + total + ' 🎉')Random Total 🎲➕🎲
Let's roll two real dice and add them! 🎲➕🎲
The total can be from 2 (1+1) all the way up to 12 (6+6)! 🔢
let die1 = Math.floor(Math.random() * 6) + 1
let die2 = Math.floor(Math.random() * 6) + 1
let total = die1 + die2
console.log('🎲 ' + die1 + ' + ' + die2 + ' = ' + total)Smallest and Biggest 🔽🔼
The smallest total is 2 (both dice show 1). 🔽
The biggest is 12 (both dice show 6). 🔼
Everything in between is possible! 🎯
console.log('Smallest: 1 + 1 = 2 🔽')
console.log('Biggest: 6 + 6 = 12 🔼')A Roll Function Again 🛠️
Let's reuse our rollDie machine for both dice! 🛠️
Cleaner code = happy coder! 😄
function rollDie() {
return Math.floor(Math.random() * 6) + 1
}
let total = rollDie() + rollDie()
console.log('Total of two dice: ' + total + ' 🎲🎲')Snake Eyes! 🐍👀
When BOTH dice show 1, it's called snake eyes! 🐍👀
Let's check for it with if and AND &&!
let die1 = 1
let die2 = 1
if (die1 === 1 && die2 === 1) {
console.log('Snake eyes! 🐍👀')
}Doubles! 👯
When both dice show the SAME number, that's doubles! 👯
Like two 4s or two 6s. Many games give a bonus for doubles! 🎁
let die1 = Math.floor(Math.random() * 6) + 1
let die2 = Math.floor(Math.random() * 6) + 1
if (die1 === die2) {
console.log('Doubles! 👯 Both showed ' + die1)
} else {
console.log('No doubles this time 🎲')
}Show It Nicely 🌈
Let's make a friendly message that shows both rolls and the total! 🌈
So fun to read! 😄
let d1 = Math.floor(Math.random() * 6) + 1
let d2 = Math.floor(Math.random() * 6) + 1
console.log('🎲 First die: ' + d1)
console.log('🎲 Second die: ' + d2)
console.log('🎉 Total: ' + (d1 + d2))Two Dice Mastered! 🎲🎲
Awesome! You can roll two dice and add them! 🎉
- Roll each die into its own box 📦
- Add them with
+➕ - Check for doubles with
===👯
console.log('Two dice mastered! ✅')
console.log('Next: tracking points! 🏅')Quick Check 🧠
Brain question! 🤔
Super Work! 🎉
You can roll two dice and add them now! 🎲🎲
- Two rolls, two boxes 📦📦
- Add with
+➕ - Doubles and snake eyes 👯🐍
Next: let's track points! 🏅
console.log('Lesson done! ⭐')
console.log('Tracking points next! 🏅')Frequently asked questions
Is the “Two Dice” lesson free?
Yes — the full text of “Two Dice” is free to read here on the web, and the Javascript for Kids course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Javascript for Kids course, upgrade to CoddyKit PRO.
What will I learn in “Two Dice”?
Add the rolls. You practise Javascript for Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Javascript for Kids?
No prior experience is required. Javascript for Kids on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Two Dice” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Javascript for Kids lesson?
Yes. Every Javascript for Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.