01 / 04
Loops, and where your data lives
INPUT · Slides
A quick recap
02 / 04
Variables and constants
Giving a value a name is a variable. const if you are not going to change it, let if you are.
And remember += and ++ for writing an update short.
const price = 320;let count = 0;count++;count++;console.log(`total ${price * count} yen`);Result
total 640 yen
03 / 04
Branching
if is the machinery for "only run this when the condition holds". What to do when it does not goes in else, and another condition part way through goes in else if.
The conditions could be comparisons like > <= ===, or those combined with && and ||.
const temp = 26;if (temp >= 30) { console.log("hot");} else if (temp >= 20) { console.log("just right");} else { console.log("cold");}Result
just right
04 / 04
Putting the two together
Variables hold values; branching picks which way to go. With both of those you can write a program that behaves differently depending on the situation.
The repetition you learn from here always comes as a set with these two. Start by getting your hands moving on the recap questions.
const money = 500;const price = 380;if (money >= price) { console.log(`change is ${money - price} yen`);} else { console.log("not enough");}Result
change is 120 yen