0Pricing
Javascript for Kids · Lesson

Making the Secret Number

Pick a random number to guess.

Making the Secret Number 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.

The Secret Number! 🤫

Time to build! First, our game needs a SECRET number. 🎲

Only the computer knows it! 🤖

Use Random 🎰

Remember Math.random()? We use it for the secret! ✨

let r = Math.random();
console.log(r);

From 1 to 10 🔢

Let us make our secret a number from 1 to 10. Times 10, floor, plus 1! 🪄

let secret = Math.floor(Math.random() * 10) + 1;
console.log(secret);

Keep It Secret! 🙊

In a real game we would NOT print the secret. 🤫

But for testing, peeking is okay! 👀

Save It in a Box 📦

We save the secret in a box called secret so we can check guesses later. 🎁

let secret = Math.floor(Math.random() * 10) + 1;
console.log("Secret is ready!");

Why 1 to 10? 🤔

1 to 10 is a nice, friendly range to guess. 😊

Not too easy, not too hard! Just right! 🐻

Make It Harder Later 🔥

Want a tougher game? Use a bigger number, like times 100! 💪

let secret = Math.floor(Math.random() * 100) + 1;
console.log("Tougher secret ready!");

A Secret-Maker Spell 🪄

Let us put it in a function so we can make a new secret any time! ✨

function makeSecret() {
  return Math.floor(Math.random() * 10) + 1;
}
console.log(makeSecret());

A New Secret Each Game 🔁

Every time we call makeSecret(), we get a fresh number! 🎲

function makeSecret() {
  return Math.floor(Math.random() * 10) + 1;
}
console.log(makeSecret());
console.log(makeSecret());

Part 1 Done! ✅

The secret number is ready! 🎉

That is the heart of our game. ❤️

Great Building! 🏗️

You used random AND a function for the secret. 🤝

You are building a real game step by step! 🚀

Quick Check 🧠

Question time! 🎯

Secret Keeper! 🏆

Yay! Your game has a secret number now. 🤫

Next, we check the player guess! 🚀

Frequently asked questions

Is the “Making the Secret Number” lesson free?

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

Pick a random number to 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 “Making the Secret Number” 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. Planning the Game
  2. Making the Secret Number
  3. Checking the Guess
  4. Winning the Game
← Back to Javascript for Kids