c# · level 1 · unit 3 · lesson 1
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Quotes turn a number into text.
5 is a number. "5" in quotes is a string that looks like one, and C# treats them very differently. 5 + 3 adds up to 8, but "5" + "3" joins into 53.
Whole numbers go in int boxes. Numbers with a decimal point, like 0.75, go in boxes. Each box only takes its own type, so text in an int box gives error CS0029.
Console.ReadLine() always gives back text. To do maths with it, it first. turns the text "12" into the number 12.
using System;
int apples = 5;
double price = 0.75;
Console.WriteLine(5 + 3);
Console.WriteLine("5" + "3");
Console.WriteLine("Apples: " + apples);
Console.WriteLine(price);
int candles = int.Parse("9");
Console.WriteLine(candles + 1); int.Parse only works on text that looks like a whole number, so int.Parse("cake") gives an error.
guess first
Two goals and one goal. What is the score?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
using System;
string homeGoals = "2";
string awayGoals = "1";
Console.WriteLine(homeGoals + awayGoals);
your turn
Your turn. Look into the future.
Choose how many years ahead to look, as a whole number, and type it in the blank on line 5. We will answer 11 to the question.
output
press run to see what happens
fix it
Dog years went wrong. Can you fix it?
output
press run to see what happens
- C# will not multiply on line 5. What type is the box called age?
Console.ReadLine()gives back text, and you cannot multiply text. Convert it into anintfirst.- Change line 4 to
int age = int.Parse(Console.ReadLine());, then press run.
nailed it
you can tell text and numbers apart. :D
- Quotes make text, even when it looks like a number.
intholds whole numbers.doubleholds decimals.int.Parseturns typed text into a whole number.
new words in your collection
- double
- convert
- int.Parse
This lesson isn’t saved. A free account remembers every lesson you finish.