← Trail· Lesson 4 of 10
See this lesson in TypeScript →
Decisions
Choose paths with if/else and switch: odd or even and a simple age rule.

A decision chooses the next step based on a condition that is true or false.
if, else and blocks
if (condition) { ... } runs a block when the condition is true. else runs the alternative block. Braces group statements, and only one of these two paths runs.
To check whether an integer is even, use numero % 2 === 0. A zero remainder means exact division by 2, including zero and negative even integers.
The example uses the simplified teaching rule age 16 or older → may vote. This is a practice condition, not a complete explanation of Brazilian election law or compulsory voting.
switch
switch (value) compares a value against each case using strict equality. break exits that path; without it, execution continues into the next case. default handles values with no matching case. The example groups Saturday and Sunday before one break.
Try it
Change idade (age), numero (number) and dia (day), one at a time. Predict the console messages.
Execute o código para ver a saída aqui.Exercise: odd or even
classificarNumero(numero) receives an integer and must return 'par' (even) or 'impar' (odd, no accent). Its return values are reversed: fix them using if/else.
Keep the function name. Use return, not only console.log. Click Verificar (Check): the cases include zero and a negative integer. Feedback and code identifiers remain in Portuguese.
Execute o código para ver a saída aqui.Edite o JavaScript e clique em Verificar.
Next step
Decisions select a path; loops repeat steps. We will combine them in FizzBuzz next.