0Pricing
Javascript for Kids · Lesson

Flip Many Times

Count heads and tails.

Flip Many Times 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.

Flip, Flip, Flip! 🪙

Hello again, coin champion! 🪙 Today we flip the coin MANY times!

And we will count how many Heads and how many Tails we get. 🔢 Let's see if it is fair!

A Counting Box 📦

To count, we need boxes to keep our score! 📦

We make heads start at 0 and tails start at 0. Then we add 1 each time. ➕

let heads = 0;
let tails = 0;
console.log('Heads so far: ' + heads);
console.log('Tails so far: ' + tails);

Adding One More ➕

When we get a Heads, we add 1 to our heads count! ➕

We write heads = heads + 1. It means: take heads and make it one bigger! 📈

let heads = 0;
heads = heads + 1;
heads = heads + 1;
console.log('Heads count: ' + heads);

Loops Save Time ⏩

Flipping 10 times by hand is so much typing! 😫 A loop does it for us! ⏩

A for loop repeats the same code again and again. Watch it count to 5! 🔢

for (let i = 1; i <= 5; i = i + 1) {
  console.log('Flip number ' + i);
}

Flip Inside the Loop 🌀

Now let's flip the coin INSIDE the loop! 🌀

Each time around, we flip once. 5 flips in a snap! ⚡

function flipCoin() {
  return Math.random() < 0.5 ? 'Heads' : 'Tails';
}
for (let i = 1; i <= 5; i = i + 1) {
  console.log('Flip ' + i + ': ' + flipCoin());
}

Count While You Flip 🔢

Now the clever part! While we flip, we count! 🔢

If it is Heads, add 1 to heads. If it is Tails, add 1 to tails. 📊

function flipCoin() {
  return Math.random() < 0.5 ? 'Heads' : 'Tails';
}
let heads = 0;
let tails = 0;
for (let i = 1; i <= 10; i = i + 1) {
  let result = flipCoin();
  if (result === 'Heads') {
    heads = heads + 1;
  } else {
    tails = tails + 1;
  }
}
console.log('Heads: ' + heads);
console.log('Tails: ' + tails);

Run It Many Times 🔁

Click Run a few times! 🔁

The numbers change every time, but Heads and Tails together always add up to 10! 🔟

function flipCoin() {
  return Math.random() < 0.5 ? 'Heads' : 'Tails';
}
let heads = 0;
let tails = 0;
for (let i = 1; i <= 10; i = i + 1) {
  if (flipCoin() === 'Heads') {
    heads = heads + 1;
  } else {
    tails = tails + 1;
  }
}
console.log('🙂 Heads: ' + heads + ' | 🪙 Tails: ' + tails);

Flip 100 Times! 💯

Computers are super fast! Let's flip 100 times! 💯

With more flips, Heads and Tails usually get close to equal. The coin is fair! ⚖️

function flipCoin() {
  return Math.random() < 0.5 ? 'Heads' : 'Tails';
}
let heads = 0;
let tails = 0;
for (let i = 1; i <= 100; i = i + 1) {
  if (flipCoin() === 'Heads') {
    heads = heads + 1;
  } else {
    tails = tails + 1;
  }
}
console.log('After 100 flips:');
console.log('🙂 Heads: ' + heads);
console.log('🪙 Tails: ' + tails);

Who Won More? 🏆

Let's find out which side came up more! 🏆

We compare the two counts with if and announce the winner! 🎉

let heads = 53;
let tails = 47;
if (heads > tails) {
  console.log('🙂 Heads won this time!');
} else if (tails > heads) {
  console.log('🪙 Tails won this time!');
} else {
  console.log('It is a tie! 🤝');
}

The Full Counter Game 🎮

Here is our complete flipping counter game! 🎮

Flip 20 times, count, and show the winner. You built this! 💪

function flipCoin() {
  return Math.random() < 0.5 ? 'Heads' : 'Tails';
}
let heads = 0;
let tails = 0;
for (let i = 1; i <= 20; i = i + 1) {
  if (flipCoin() === 'Heads') heads = heads + 1;
  else tails = tails + 1;
}
console.log('🙂 Heads: ' + heads + ' | 🪙 Tails: ' + tails);
if (heads > tails) console.log('Heads wins! 🎉');
else if (tails > heads) console.log('Tails wins! 🎉');
else console.log('Tie! 🤝');

You Are a Coin Master! 🏆

WOW! 🏆 You finished the whole Coin Flip Game!

  • 📦 Counting with variables
  • ⏩ Loops repeat work for us
  • 🔢 Count Heads and Tails while flipping
  • 🏆 Find the winner

You are a real coder now! Keep flipping! 🪙

Quick Check ✅

Last brain check for this game! 🧠 What does a for loop help us do?

Lesson Recap 🎀

Hooray! 🎀 You completed the Coin Flip Game! You learned:

  • 📦 Counters start at 0 and grow with + 1
  • for loops repeat the flip
  • 🔢 Count Heads and Tails as you go
  • 🏆 Compare counts to find the winner

Amazing work, coding champion! 👑

Frequently asked questions

Is the “Flip Many Times” lesson free?

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

Count heads and tails. 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 “Flip Many Times” 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