vibecodai logovibecodai
← All JavaScript lessons

JavaScript · Lesson 3 · 12 min

Making Decisions with if

Run different code depending on conditions — yes or no, true or false.

You will learn

  • Write if and else statements
  • Compare values with === and >
  • Branch your program based on conditions

Programs need to make choices. Should the character jump? Is the score high enough to win? if statements check a condition and run code only when it is true.

Comparisons

Use === to check if two values are equal. Use >, <, >=, and <= for numbers. The result is true or false — called a boolean.

else

Add else to run different code when the condition is false. Try changing the score in the example to see both paths.

Try it yourself

Output

Press Run code to see results here.

Tip: Change score to 95 or 50 and run again.