Who Wins?
Compare choices.
Who Wins? is a free Javascript for Kids lesson on CoddyKit — lesson 3 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.
Time to Find the Winner! 🏆
You and the computer both made a pick. Now the big question: who wins? 🤔
We'll teach the code to compare the two picks! ⚖️
let you = 'rock'
let computer = 'scissors'
console.log('You: ' + you + ' ✊')
console.log('Computer: ' + computer + ' ✂️')Check for a Tie First 🤝
The easiest check is a tie. If both picks are the same, nobody wins!
We use === to see if they match. 🟰
let you = 'paper'
let computer = 'paper'
if (you === computer) {
console.log('It is a tie! 🤝')
}The if Statement 🔀
if means "only do this when something is true". 🔀
If the question inside the ( ) is true, the code inside { } runs!
let you = 'rock'
if (you === 'rock') {
console.log('You picked rock! ✊')
}When You Win ✊
You win if you pick Rock and the computer picks Scissors! 💥
Rock smashes scissors, so YOU are the champ! 🏆
let you = 'rock'
let computer = 'scissors'
if (you === 'rock' && computer === 'scissors') {
console.log('You win! ✊ beats ✂️ 🏆')
}The Word AND 🔗
That && means AND. 🔗
It checks TWO things at once. Both must be true!
You pick rock AND computer picks scissors. ✊✂️
let a = true
let b = true
if (a && b) {
console.log('Both are true! ✅')
}All the Ways You Win 🌟
You win in three ways:
- Rock ✊ beats Scissors ✂️
- Paper 📄 beats Rock ✊
- Scissors ✂️ beats Paper 📄
We check all three! 🎯
let you = 'paper'
let computer = 'rock'
if (you === 'paper' && computer === 'rock') {
console.log('You win! 📄 beats ✊ 🏆')
}The Word OR 🔀
|| means OR. 🔀
It is true if any part is true. We can list all your winning chances together!
let win = true
let lose = false
if (win || lose) {
console.log('At least one is true! ✅')
}Else If for Losing 😅
If you didn't tie and didn't win... then you lost! 😅
We use else to say "otherwise, do this".
let youWon = false
if (youWon) {
console.log('You win! 🏆')
} else {
console.log('Computer wins! 🤖')
}Putting It All Together 🧩
Now let's combine tie, win, and lose into one game check! 🧩
First check tie, then check if you win, otherwise computer wins. ⚖️
let you = 'scissors'
let computer = 'paper'
if (you === computer) {
console.log('Tie! 🤝')
} else if (you === 'scissors' && computer === 'paper') {
console.log('You win! ✂️ beats 📄 🏆')
} else {
console.log('Computer wins! 🤖')
}A Winner Function 🛠️
Let's wrap the whole thing in a function! Give it your pick and the computer's pick, and it tells you who wins. 🛠️
function whoWins(you, comp) {
if (you === comp) return 'Tie! 🤝'
if ((you === 'rock' && comp === 'scissors') ||
(you === 'paper' && comp === 'rock') ||
(you === 'scissors' && comp === 'paper')) {
return 'You win! 🏆'
}
return 'Computer wins! 🤖'
}
console.log(whoWins('rock', 'paper'))You Can Judge the Game! ⚖️
Wow! Your code can now decide the winner! 🎉
- Same pick = tie 🤝
&&means AND 🔗||means OR 🔀elsemeans otherwise 😄
console.log('You can judge the game! ✅')
console.log('Next: play again! 🔁')Quick Check 🧠
Brain time! 🤔
Fantastic! 🎉
You taught the code to pick a winner! 🏆
- Check for a tie with
===🤝 - Check your wins with
&&and||🔗 - Use
elsefor the rest 😄
Next: let's play again in a loop! 🔁
console.log('Lesson done! ⭐')
console.log('Let us loop the game! 🔁')Frequently asked questions
Is the “Who Wins?” lesson free?
Yes — the full text of “Who Wins?” 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 “Who Wins?”?
Compare choices. 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 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Who Wins?” 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.
All lessons in this course
- The Rules
- Computer Picks
- Who Wins?
- Play Again