0Pricing
Javascript for Kids · Lesson

Picking a Random Item

Choose a random thing from a list.

Picking a Random Item 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.

Pick a Surprise! 🎁

What if the computer picked a random snack for you? 🍕🍦🍪

Let us learn to pick a random item from a list! 📋

A List of Things 📋

An array is a list. We hold many things in one box! 📦

let snacks = ["pizza", "cookie", "apple"];
console.log(snacks);

Items Have Spots 🔢

Each item has a spot number, starting at 0! 🧮

pizza is 0, cookie is 1, apple is 2. 😄

let snacks = ["pizza", "cookie", "apple"];
console.log(snacks[0]);

Pick by Spot 👉

We grab an item using its spot number in [ ]. 🎯

let snacks = ["pizza", "cookie", "apple"];
console.log(snacks[2]);

How Long Is It? 📏

.length tells us how many items are in the list! 🔢

let snacks = ["pizza", "cookie", "apple"];
console.log(snacks.length);

A Random Spot 🎲

Remember random dice? We pick a random spot the same way! 🎰

let snacks = ["pizza", "cookie", "apple"];
let spot = Math.floor(Math.random() * 3);
console.log(spot);

Grab the Random Item! 🎁

Now use that random spot to pick a snack! 🍪

let snacks = ["pizza", "cookie", "apple"];
let spot = Math.floor(Math.random() * 3);
console.log(snacks[spot]);

Use .length for Safety 🛡️

Instead of typing 3, use .length. It works for any list size! 🎯

let snacks = ["pizza", "cookie", "apple"];
let spot = Math.floor(Math.random() * snacks.length);
console.log(snacks[spot]);

Make a Picker Spell 🪄

Let us put it in a function to pick from ANY list! ✨

function pick(list) {
  let spot = Math.floor(Math.random() * list.length);
  return list[spot];
}
console.log(pick(["red", "blue", "green"]));

Pick Anything! 🌈

Now you can pick a random color, animal, or name! 🐶🐱🐰

Press Run again for a new surprise! 🎉

You Are a Picker Pro! 🎉

Great work! You pick random items from lists now. 📋

This is super useful for games!

Quick Check 🧠

Question time! 🎯

List Wizard! 🏆

Hooray! You can pick random items! 🎁

Next, we build a lucky number game! 🚀

Frequently asked questions

Is the “Picking a Random Item” lesson free?

Yes — the full text of “Picking a Random Item” 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 “Picking a Random Item”?

Choose a random thing from a list. 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 “Picking a Random Item” 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. Making Random Numbers
  2. Rolling a Dice
  3. Picking a Random Item
  4. A Lucky Number Game
← Back to Javascript for Kids