0Pricing
Javascript for Kids · Lesson

Checking the Guess

Compare results.

Checking the Guess 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.

Did You Win? 🏆

Welcome back! 🪙 Now for the most exciting part: checking the guess! 🔍

We need to compare what the player guessed with what the coin showed. If they match, the player WINS! 🏆

Comparing Two Things ⚖️

To compare two things in JavaScript, we use === (three equal signs). ⚖️

It asks: are these two things exactly the same? It answers true or false. ✅❌

console.log('Heads' === 'Heads');
console.log('Heads' === 'Tails');

True or False? 🤔

See? Same words give true ✅, different words give false ❌.

This is exactly how we check if a guess is correct! 🎯

let guess = 'Heads';
let result = 'Heads';
console.log('Are they the same? ' + (guess === result));

The Big Check 🔍

Let's use if to react to the comparison! 🔍

If the guess matches the result, we say You win! 🎉

let guess = 'Heads';
let result = 'Heads';
if (guess === result) {
  console.log('You win! 🎉');
}

What if You Lose? 😅

But what if the guess does NOT match? We use else for that! 😅

Then we say Try again! No worries, it is just a game! 🪙

let guess = 'Heads';
let result = 'Tails';
if (guess === result) {
  console.log('You win! 🎉');
} else {
  console.log('Aw, try again! 😅');
}

Real Coin, Real Check 🪙

Now let's use a REAL random flip with our coin machine! 🪙

The guess stays Heads, but the coin is a surprise. Run it a few times! 🔁

function flipCoin() {
  if (Math.random() < 0.5) {
    return 'Heads';
  } else {
    return 'Tails';
  }
}
let guess = 'Heads';
let result = flipCoin();
console.log('You guessed: ' + guess);
console.log('Coin shows: ' + result);
if (guess === result) {
  console.log('You win! 🎉');
} else {
  console.log('Try again! 😅');
}

A Checking Function 🛠️

Let's put the check inside its own helper machine! 🛠️

The function checkGuess takes the guess and the result, then tells us who won. 🏆

function checkGuess(guess, result) {
  if (guess === result) {
    return 'You win! 🎉';
  } else {
    return 'Try again! 😅';
  }
}
console.log(checkGuess('Heads', 'Heads'));
console.log(checkGuess('Heads', 'Tails'));

Put It All Together 🧩

Now let's connect everything: flip, guess, and check! 🧩

This is a complete mini game! 🎮

function flipCoin() {
  return Math.random() < 0.5 ? 'Heads' : 'Tails';
}
function checkGuess(guess, result) {
  return guess === result ? 'You win! 🎉' : 'Try again! 😅';
}
let guess = 'Tails';
let result = flipCoin();
console.log('Guess: ' + guess + ' | Coin: ' + result);
console.log(checkGuess(guess, result));

Cheer for the Winner 🎊

Let's make winning extra exciting with more emojis! 🎊

A big celebration makes the game more fun! 🥳

function checkGuess(guess, result) {
  if (guess === result) {
    return '🎉🎊 YOU WIN! Amazing! 🥳';
  } else {
    return '😅 So close! Give it another go! 🔁';
  }
}
console.log(checkGuess('Heads', 'Heads'));

Play Many Rounds 🎮

Let's play 3 rounds in a row! 🎮

Each round we flip and check. Count how many you win! 🏆

function flipCoin() {
  return Math.random() < 0.5 ? 'Heads' : 'Tails';
}
let guess = 'Heads';
console.log('Round 1: ' + flipCoin());
console.log('Round 2: ' + flipCoin());
console.log('Round 3: ' + flipCoin());
console.log('You always guessed: ' + guess);

You Can Check Guesses! 🏆

Super job! 🏆 You learned to check if a guess is correct!

  • ⚖️ === compares two things
  • ✅ It gives true or false
  • 🔍 if/else reacts to the answer

Next, we will flip MANY times and count! 🔢

Quick Check ✅

Brain time! 🧠 Which symbol do we use to check if two things are exactly the same?

Lesson Recap 🎀

Fantastic work, game checker! 🎀 Today you learned:

  • ⚖️ Compare with ===
  • ✅ Get true or false
  • 🔍 React with if and else
  • 🛠️ A checkGuess function keeps it tidy

Next up: flipping many times and counting! 🔢

Frequently asked questions

Is the “Checking the Guess” lesson free?

Yes — the full text of “Checking the Guess” 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 “Checking the Guess”?

Compare results. 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 “Checking the Guess” 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

  1. Heads or Tails
  2. Guessing
  3. Checking the Guess
  4. Flip Many Times
← Back to Javascript for Kids