0Pricing
Javascript for Kids · Lesson

Picking an Operation

Choose with if.

Picking an Operation 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.

Let the User Choose! 🎛️

A real calculator lets you PICK what math to do. Press +, or -, or ×!

To make choices in code, we use the magic word if. 🤔

What Is if? 🚦

if checks: is something TRUE? If yes, it runs the code inside its { }!

It is like a guard at a door who only lets you in IF you have a ticket. 🎟️

let op = 'add'
if (op === 'add') {
  console.log('You picked adding!')
}

Three Equals?! 🟰🟰🟰

To CHECK if two things match, we use === (three equals). It asks 'are these the same?'

Remember: ONE equals stores, THREE equals checks!

let op = 'add'
if (op === 'add') {
  console.log('Yes, they match!')
}

Add If Chosen ➕

Let us add the numbers ONLY if the user picked 'add'!

let a = 5
let b = 3
let op = 'add'
if (op === 'add') {
  console.log(a + b)
}

Else If for More Choices 🔀

What about subtract? We use else if to check another choice!

let a = 5
let b = 3
let op = 'subtract'
if (op === 'add') {
  console.log(a + b)
} else if (op === 'subtract') {
  console.log(a - b)
}

All Four Choices 🎯

Let us handle every operation with if and else if!

let a = 12
let b = 4
let op = 'multiply'
if (op === 'add') {
  console.log(a + b)
} else if (op === 'subtract') {
  console.log(a - b)
} else if (op === 'multiply') {
  console.log(a * b)
} else if (op === 'divide') {
  console.log(a / b)
}

The else Catch-All 🥅

What if the user types something weird? else catches everything that did not match!

let op = 'banana'
if (op === 'add') {
  console.log('Adding')
} else {
  console.log('I do not know that one!')
}

Try a Different Op 🔄

Change op to 'divide' and see a different answer! The if picks the right math.

let a = 20
let b = 5
let op = 'divide'
if (op === 'add') {
  console.log(a + b)
} else if (op === 'divide') {
  console.log(a / b)
}

Friendly Messages 💬

Let us tell the user WHICH math we did, not just the number!

let a = 6
let b = 2
let op = 'subtract'
if (op === 'subtract') {
  console.log(a + ' minus ' + b + ' is ' + (a - b))
}

Symbols as Choices ➕➖

We can use symbols like '+' as the choice instead of words!

let a = 4
let b = 4
let op = '+'
if (op === '+') {
  console.log(a + b)
} else if (op === '*') {
  console.log(a * b)
}

Your Turn to Choose 🌟

Change op to 'multiply' and run! Watch the if pick the right path. 🎯

let a = 7
let b = 3
let op = 'add'
if (op === 'add') {
  console.log(a + b)
} else if (op === 'multiply') {
  console.log(a * b)
}

Quick Check ✅

Choosing brain check! 🧠

Picking an Operation Recap 🎉

You can make choices now! 🎛️ Your calculator picks the math.

  • if runs code when something is true
  • === checks if two things match
  • else if and else handle more choices

Last lesson: showing the final answer nicely! 📣

Frequently asked questions

Is the “Picking an Operation” lesson free?

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

Choose with if. 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 an Operation” 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. Two Numbers
  2. Doing Math
  3. Picking an Operation
  4. Showing the Answer
← Back to Javascript for Kids