Menu
Coddy logo textTech

Recap - Simple Calculator

Part of the Fundamentals section of Coddy's Ruby journey — lesson 23 of 88.

challenge icon

Challenge

Easy

You are provided with the following variables:

operator = "*"
num1 = 12
num2 = 4

Build a simple calculator that performs the correct arithmetic operation based on the operator value.

Use if-else statements to check the operator and output the result:

  • If operator is "+", print the sum of num1 and num2
  • If operator is "-", print the difference (num1 - num2)
  • If operator is "*", print the product
  • If operator is "/", print the quotient (num1 / num2)

Output only the numeric result.

Try it yourself

operator = "*"
num1 = 12
num2 = 4

# TODO: Write your code below
# Use if-else statements to check the operator and perform the correct operation
# Output the result using puts

All lessons in Fundamentals