انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents

🛠️ Project: the calculator

Section 3: Typing and mathsLesson 3.2 · ⏱ 14 min
🎯 Project goal
Two numbers in two boxes, and four buttons + − × ÷, and the result big under them. And it doesn't accept dividing by zero.
The design: two text boxes, a horizontal row with the four buttons, and a label for the result
The design: two text boxes, a horizontal row with the four buttons, and a label for the result
Every button has its operation, and the ÷ button asks first: is the second number zero?
Every button has its operation, and the ÷ button asks first: is the second number zero?
12 × 3 = 36 in the lab
12 × 3 = 36 in the lab
  • 🔢 number from turns the typed text into a number. Without it 12 + 3 becomes “123”, because the app sticks the two texts together.
  • if … else: if the second number is 0 we write a message, otherwise we divide.
🖥️ What happens on the stage?
We tried it in the lab: 12 + 3 = 15, 12 ÷ 3 = 4, 12 ÷ 0 → “You can't divide by zero”, and 12 × 3 = 36.
  1. Add a “Clear” button that empties the two boxes.
  2. Add a power button ^ from the maths block.

📌 Another example: the area of a rectangle

Length × width.

The design
The design
The blocks
The blocks
In the lab: 6 × 4
In the lab: 6 × 4
✍️ Practise
Practice: a calculator.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

An adding-only calculator.

👀 Show the solution
The design
The design
The blocks
The blocks
In the lab
In the lab

Result: 12 + 7 = 19

Medium

The average of two numbers.

👀 Show the solution
The design
The design
The blocks
The blocks
In the lab
In the lab

Result: (10 + 20) ÷ 2 = 15

Hard

Which of the two numbers is bigger?

👀 Show the solution
The design
The design
The blocks
The blocks
In the lab
In the lab

Result: The bigger: 42

Finished the lesson? Mark it so your progress counts.