Day 3: Logic
Wrap up
Congratulations on finishing another day 😀
Conditional logic and this kind of flow control is a big part of programming and, while it might seem confusing right now, in time it will become second nature.
This is the first time we have taken an earlier concept, booleans (true/false), and combined it with something new so if you're brain is spinning that's to be expected.
Exercise
To wrap up today I have a small task for you to complete. In the playground below we have 2 weather inputs, temperature
and conditions
.
temperature
can be any number and conditions
can be any of: raining
, sunny
and foggy
.
Based on the conditions and temperature we need a script that will console.log()
a message for what to wear. Let's keep it to 6 outputs so it's not too much code, the clothing advice will be:
Conditions | Below 15°C | Above 15°C |
---|---|---|
Raining | Thick Coat | Thin Coat |
Sunny | Light Jumper | T-Shirt |
Foggy | Bright Coat | Where Are You? |
Once you've got that working, then add an override variable called bothered
, if bothered === true
then run through the above code and console.log()
the result. If the user is not bothered (=== false
) then skip the whole section and console.log()
"Best of luck!"
(Remember you can make the coding playground area wider by hovering on and dragging the vertical divider)