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

The switch and the condition: the lamp

Section 4: ConditionsLesson 4.1 · ⏱ 8 min
Before tapping: the switch is off and the screen is dark
Before tapping: the switch is off and the screen is dark
When Switch1 changes: if it is on, the screen is light yellow and ☀️, otherwise it is dark blue and 🌙
When Switch1 changes: if it is on, the screen is light yellow and ☀️, otherwise it is dark blue and 🌙
We tapped the switch, and the lamp lit up
We tapped the switch, and the lamp lit up
  • when Switch1 changes works every time we turn the switch on or off.
  • if … else chooses between two ways: if the switch is on do this, otherwise do that.

📌 Another example: night mode

The switch changes the screen to night and day.

The design
The design
The blocks
The blocks
In the lab: day
In the lab: day
✍️ Practise
The challenge: the switch and the colours.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

The switch shows or hides the picture.

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

Result: the picture disappeared.

Medium

The switch writes “On” or “Off”.

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

Result: On ✅

Hard

A lock with two switches: it only opens if both are on.

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

Result: one switch: locked. Both: open.

Finished the lesson? Mark it so your progress counts.