Conditionals and loops are two of the most important
concepts in JavaScript. A conditional says, “If something is true, do this. Otherwise, do that.” For example,
if you do your homework, you can have ice cream,
but if you don’t do your homework, you don’t get the
ice cream. A loop says, “As long as something is true,
keep doing this.” For example, as long as you are
thirsty, keep drinking water.
90 Chapter 6
Conditionals and loops are powerful concepts that are key
to any sophisticated program. They are called control structures
because they allow you to control which parts of your code are
executed when and how often they’re executed, based on certain
conditions you define.
We first need to go over how to embed JavaScript in our
HTML file so we can start creating longer programs than we’ve
looked at so far.