0Pricing
Javascript for Kids · Lesson

Guessing

Let the player guess.

Guessing 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.

Time to Guess! 🤔

Welcome back, coin master! 🪙 Now we will let a player guess before the flip!

This is what makes it a real game. You guess, the coin flips, and we see if you were right! 🎉

A Guess is a Choice 🎯

The player can only pick one of two things: Heads or Tails. 🎯

Let's save the player's guess in a box (variable) called guess. 📦

let guess = 'Heads';
console.log('The player guessed: ' + guess);

Try Tails Instead 🪙

The guess can be anything we want! Let's change it to Tails. 🪙

The box just holds whatever we put inside it. 📦

let guess = 'Tails';
console.log('The player guessed: ' + guess);

Show a Friendly Message 💬

Let's make the game talk to the player! 💬

We add a fun sentence so the player feels welcome. 😄

let guess = 'Heads';
console.log('🪙 Coin Flip Game!');
console.log('You picked: ' + guess);
console.log('Lets see if you are right... 🤞');

Bring Back the Flip 🔁

Remember our coin machine from before? 🤖 Let's bring it back!

Our flipCoin() function still flips Heads or Tails for us. 🪙

function flipCoin() {
  if (Math.random() < 0.5) {
    return 'Heads';
  } else {
    return 'Tails';
  }
}
console.log('The coin flipped: ' + flipCoin());

Guess AND Flip Together 🤝

Now let's do both! First the player guesses, then the coin flips. 🤝

We will print both so we can compare them later. 👀

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('The coin shows: ' + result);

Run a Few Times 🔁

Click Run a few times! 🔁

Your guess stays the same, but the coin keeps changing. Sometimes they match, sometimes they don't! 😆

function flipCoin() {
  if (Math.random() < 0.5) {
    return 'Heads';
  } else {
    return 'Tails';
  }
}
let guess = 'Tails';
let result = flipCoin();
console.log('You guessed: ' + guess);
console.log('The coin shows: ' + result);

A Guessing Helper 🛠️

Let's make a little helper to show the guess nicely. 🛠️

The function showGuess takes the guess and prints a fun message! 🎉

function showGuess(guess) {
  console.log('🙋 You guessed: ' + guess + '!');
}
showGuess('Heads');
showGuess('Tails');

Random Guess Robot 🤖

What if the computer guessed too? 🤖 Let's make a robot player!

We can use flipCoin() again to make the robot's guess. So sneaky! 😎

function flipCoin() {
  if (Math.random() < 0.5) {
    return 'Heads';
  } else {
    return 'Tails';
  }
}
let robotGuess = flipCoin();
console.log('🤖 Robot guesses: ' + robotGuess);

Both Players Guess 👫

Now you AND the robot both guess! 👫

We print both guesses. Who do you think will win? 🏆

function flipCoin() {
  if (Math.random() < 0.5) {
    return 'Heads';
  } else {
    return 'Tails';
  }
}
let yourGuess = 'Heads';
let robotGuess = flipCoin();
console.log('🙋 You guess: ' + yourGuess);
console.log('🤖 Robot guesses: ' + robotGuess);

Great Guessing! 🏆

Awesome! 🏆 You learned how to make a player guess!

  • 📦 We store the guess in a variable
  • 💬 We print a friendly message
  • 🤝 We guess AND flip together

Next we will check if the guess matches the flip! 🔍

Quick Check ✅

Brain power time! 🧠 Where do we keep the player's guess so we can use it later?

Lesson Recap 🎀

Well done, guessing genius! 🎀 Today you learned:

  • 📦 Save a guess in a variable
  • 💬 Print friendly messages
  • 🤖 Even a robot can guess with flipCoin()
  • 🤝 Guess and flip together

Next lesson: we check who is right! 🔍

Frequently asked questions

Is the “Guessing” lesson free?

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

Let the player guess. 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 “Guessing” 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