Winning the Game
Celebrate when the guess is correct.
Winning the Game is a free Javascript for Kids lesson on CoddyKit — lesson 4 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 Celebrate! 🎉
The best part of a game is WINNING! 🏆
Let us make our game cheer when the player guesses right! 🎊
The Winning Moment 🎯
The player wins when the guess equals the secret. 🟰
let secret = 6;
let guess = 6;
if (guess === secret) {
console.log("You won! Amazing!");
}A Big Celebration! 🎆
Let us make the win super exciting with lots of cheering! 📣
let secret = 6;
let guess = 6;
if (guess === secret) {
console.log("You won!");
console.log("You are a champion!");
console.log("Hooray!");
}Count the Tries 🔢
A fun idea: count how many guesses it took! 🧮
let tries = 3;
console.log("You won in " + tries + " tries!");Fewer Tries, Bigger Win! 🌟
The fewer tries, the better the player did! 🏅
We can make the message extra happy for quick wins! ⚡
Put It All Together 🧩
Now we combine the hint AND the win celebration! 🎉
function play(guess) {
let secret = 6;
if (guess < secret) return "Higher!";
if (guess > secret) return "Lower!";
return "YOU WIN! Hooray!";
}
console.log(play(6));The Full Game! 🎮
Here is our whole game in one spell. Try different guesses! ✨
function play(guess) {
let secret = Math.floor(Math.random() * 10) + 1;
if (guess === secret) return "WIN! It was " + secret;
if (guess < secret) return "Higher!";
return "Lower!";
}
console.log(play(5));Add a Trophy! 🏆
Let us add a trophy emoji when the player wins! 🎊
let won = true;
if (won) {
console.log("🏆 WINNER! 🏆");
}Play Again? 🔁
Good games let you play again! We just call our spell once more. 🎮
function play(guess) {
let secret = 4;
return guess === secret ? "WIN!" : "Try again!";
}
console.log(play(4));
console.log(play(2));You Built a Whole Game! 🏗️
Secret number, hints, AND a win celebration! 🎉
You are a real game maker now! 🎮
Look How Far You Came! 🌈
You learned functions, booleans, random, and built games! 🚀
You should be SO proud. 🥳
Quick Check 🧠
The final question! 🎯
Game Champion! 🏆
HOORAY! You finished the whole Number Guessing game! 🎊🎉
You are an amazing coder. Keep building awesome things! 🚀✨
Frequently asked questions
Is the “Winning the Game” lesson free?
Yes — the full text of “Winning the Game” 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 “Winning the Game”?
Celebrate when the guess is correct. 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 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Winning the Game” 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
- Planning the Game
- Making the Secret Number
- Checking the Guess
- Winning the Game