Here's a simple JavaScript program that demonstrates the use of conditional statements:
This program uses the if
and else
statements to check the value of the variable x
and execute different statements based on the result of the check.
The first if
statement checks if the value of x
is greater than 0, and if so, it executes the statement inside the if block and writes "x is greater than 0" to the screen. If the condition is false, it goes to the else block and writes "x is less than or equal to 0" to the screen.
The second if
statement uses an else if
block to check if the value of x
is equal to 5, if true it writes "x is equal to 5" to the screen. If the first condition is false, it goes to the next else if block which checks if the value of x
is less than 5, if true it writes "x is less than 5" to the screen. If both the conditions are false, the code goes to the else block and writes "x is greater than 5" to the screen.
You can use any text editor that supports HTML and JavaScript like Visual Studio Code, Sublime Text, Atom or any other text editor that supports javascript.
No comments:
Post a Comment