c# · level 1 · unit 4 · lesson 3
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
adds more paths to the fork.
Some questions have more than two answers. else if adds another condition to check when the ones above it were false. C# checks from the top down and runs only the first block whose condition is true.
Every gives true or false. < means less than, > more than, <= less than or equal to, >= more than or equal to, and != not equal to.
== and != work on text too, letter by letter. Capitals count, so "Cat" == "cat" is false.
using System;
int temperature = 12;
if (temperature < 5)
{
Console.WriteLine("Wear a big coat.");
}
else if (temperature < 15)
{
Console.WriteLine("A jumper will do.");
} In <= and >= the = always comes second, never first.
guess first
Big slide or small slide? Guess first.
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
using System;
int height = 120;
if (height > 120)
{
Console.WriteLine("Hop on the big slide!");
}
else if (height >= 100)
{
Console.WriteLine("Try the small slide.");
}
your turn
Your turn. How many sweets have you got?
Choose a number of sweets and a comparison sign, like < or >=, so that the else if message shows.
output
press run to see what happens
fix it
The top score gets no gold star. Fix the order.
output
press run to see what happens
- C# checks from the top and stops at the first
true. Which check istruefirst for 95? - 95 is at least 50, so the gold star never gets a chance. The bigger check needs to come first.
- Swap them: check
score >= 90first with its gold star, thenscore >= 50with its pass message.
nailed it
your code can pick from many paths. :D
else ifchecks a new condition when the ones above werefalse.- C# stops at the first
truecondition. ==compares text letter by letter, capitals included.
new words in your collection
- else if
- comparison
This lesson isn’t saved. A free account remembers every lesson you finish.