Every condition in a program is either true or false. Logic words — AND, OR and NOT — combine conditions: AND needs both parts true, OR needs at least one, and NOT flips true to false.
Apa yang akan dipelajari anak anda
- Decide whether simple statements are true or false
- Use AND: both parts must be true
- Use OR: at least one part must be true
- Use NOT to reverse a condition
AND, OR, NOT
“The number is more than 2 AND less than 6” is true for 3, 4 and 5 only. “Less than 2 OR more than 6” is true for 0, 1, 7, 8 and up. A game might give a bonus only if score > 100 AND lives > 0 — miss either and there’s no bonus.
Contoh soalan
Berikut ialah beberapa soalan seperti dalam misi pertama. Bolehkah anda menjawabnya?
1. In coding, a condition is always either…
- big or small
- true or false
- red or blue
- up or down
Tunjuk jawapan
Jawapan: true or false. Conditions are checked as true or false.
2. True or false: 2 > 9
- False
- True
Tunjuk jawapan
Jawapan: Salah. 2 is not greater than 9.
3. “You can have juice OR milk” means…
- you must have both
- you get water
- you get neither
- you can choose either one
Tunjuk jawapan
Jawapan: you can choose either one. OR is true if at least one part is true.
4. True or false? (OR)
- false OR false
- false OR true
- true OR true
- true OR false
Bakul: True · False
Tunjuk jawapan
Jawapan: True: false OR true, true OR false, true OR true · False: false OR false. OR is true when at least one side is true.
Tip untuk orang dewasa
- Play “Stand up if you have a pet AND you like apples”, then try OR.
- Ask true-or-false questions at dinner: “Broccoli is blue OR carrots are orange.”