What's a Condition?
Learn how to write conditional statements in JavaScript.
We'll cover the following
Suppose we want to write a program that asks the user to enter a number and then displays a message if the number is positive. Here is the corresponding algorithm.
Enter a number
If the number is positive
Display a message
The message should display only if the number is positive; this means it’s “subject” to a condition.
The if
statement
Here’s how you translate the program to JavaScript.
Get hands-on with 1400+ tech skills courses.