انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Block: home
0. Lab tour1
1. Getting started5
2. Motion5
3. Looks and sound5
4. Events4
5. Loops5
6. Conditions and sensing4
7. Variables and randomness4
8. Project: the “Catch Robo” game3
9. Messages: characters talk to each other4
10. Clones: one character, many copies4
11. My Blocks: make a new block3
12. Operators and time4
13. The pro project: a jumping game4

Even or odd? (mod and if-else)

Section 12: Operators and timeLesson 12.1 · ⏱ 8 min

mod gives the remainder of a division: 7 mod 2 = 1, and 8 mod 2 = 0. So a number is even if its remainder when divided by 2 is zero. if … else runs one part if the condition is true, and the other part if it isn't. join sticks two pieces of text together.

Blocks: when 🚩 clicked, go to x: (0) y: (-40), set (n) to (pick random 1 to 100), if <(n mod 2 = 0)> then
Robo picked a random number and said whether it is even or odd
Robo picked a random number and said whether it is even or odd

📌 Another example: big or small?

Robo picks a number from 1 to 100: if it is more than 50 it is big, else it is small.

Blocks: when 🚩 clicked, go to x: (0) y: (-40), set (n) to (pick random 1 to 100), if <(n > 50)> then
A random number
A random number
✍️ Practise
Run the example 5 times and check every number yourself. Then make Robo say whether the number can be divided by 3.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

Count from 1 to 10, but Robo says only the even numbers (i mod 2 = 0).

👀 Show the solution
Blocks: when 🚩 clicked, set (i) to (0), repeat (10)
The last even number: 10
The last even number: 10
Medium

From 1 to 30: Robo says only the multiples of 5 (5, 10, 15…).

👀 Show the solution
Blocks: when 🚩 clicked, set (i) to (0), repeat (30)
Reached 30
Reached 30
Hard

The “Fizz Buzz” game from 1 to 15: a multiple of 3 says “Fizz”, a multiple of 5 says “Buzz”, a multiple of both (15) says “Fizz Buzz”, and anything else says the number.

👀 Show the solution
Blocks: when 🚩 clicked, set (i) to (0), repeat (15)
The number 15: Fizz Buzz
The number 15: Fizz Buzz
Finished the lesson? Mark it so your progress counts.