Conditionals
Most real logic isn't one straight line - it depends. if runs a block only
when a condition is true; else if gives it another condition to try when the
first one fails; else catches whatever's left. JavaScript checks them in
order, top to bottom, and runs the first block whose condition matches.
Inside a function, each branch usually ends in its own return - as soon as
one fires, the function is done, and the branches below it never run. You don't
need an else at the very end if the last branch already returns.
Your task: write a function classify(n) that returns "positive" if n
is greater than 0, "negative" if it's less than 0, and "zero" otherwise.
You'll practice:
- Chaining conditions with
if / else if / else
- Returning different values from different branches