The if Statement part 1

The if Statement



Very often when you write code, you want to perform different actions based on different conditions.
You can do this by using conditional statements in your code.

Use if to specify a block of code that will be executed if a specified condition is true.if (condition) {
statements
}

The statements will be executed only if the specified condition is true.

Example:
var myNum1 = 7;
var myNum2 = 10;
if (myNum1 < myNum2) {
alert("JavaScript is easy to learn.");
}
Try It Yourself

Result:
As seen in the picture above, the JavaScript alert() method is used to generate a popup alert box that contains the information provided in parentheses.
Please add the corresponding characters to complete the statement:

if 
 
 
var1 > var2
 
 

 
 

   document.write("OK");
 
 

Comments

Popular posts from this blog

Introducing object part 3

Comparison Operators part 2

Module 2