Picking an Operation
Choose with if.
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!')
}All lessons in this course
- Two Numbers
- Doing Math
- Picking an Operation
- Showing the Answer