If else if statement in Java Script




If Statement: If statement is execute when condition is true. If condition is not satisfied then statement is not execute. It means we get result when condition is satisfied and condition is not satisfy then result is not show.

Syntax:

If (Condition)

statement;


Program:

<html>

<body>

<h2>Enter Age</h2>

<input id="age"><br><br>

<button onclick="myfun()">check my age </button>

<br><br>

<script type="text/javascript">

function myfun()

{

var age=document.getElementById('age').value;

if(age>18)

{

document.write("Ealder");

}

}

</script>

</body>

</html>




If and Else statement :

If and else statement is also conditional statement. In this statement when condition is true then program is execute and condition is not satisfied then statement is execute. It means we get result when condition is satisfied and condition is not satisfy then result also show.

Syntax:

If (Condition)

statement;

else

statement;


Program:

<html>

<body>

<h2>Enter Age</h2>

<input id="age"><br><br>

<button onclick="myfun()">check my age </button>

<br><br>

<script type="text/javascript">

function myfun()

{

var age=document.getElementById('age').value;

if(age>18)

{

document.write("Ealder");

}


else

{

document.write("child");

}

}

</script>

</body>

</html>




If else if statement in Java Script; We use this statement when we need more than two condition.

Syntax:

If (Condition)

statement;

else if (condition)

statement;

else

statement;

Program:

<html>

<body>

<h2>Enter Age</h2>

<input id="age"><br><br>

<button onclick="myfun()">check my age </button>

<br><br>

<script type="text/javascript">

function myfun()

{

var age=document.getElementById('age').value;

if(age>18)

{

document.write("Ealder");

}

else if(age==18)

{

document.write("Younger");

}

else

{

document.write("child");

}

}

</script>

</body>

</html>



28 views0 comments

Recent Posts

See All

Java Script program to find simple interest

<html> <head> <title> form event</title> <script language="javascript"> function si(fnm) { P=fnm.t1.value R=fnm.t2.value T=fnm.t3.value fnm.t4.value=(P*R*T)/100 } </script> </head> <body> <form> <br>