js2

Share this page :

JavaScript Comparison Operators:

== equal to
!= not equal
> greater than
< less than
>= greater than or equal to
<= less than or equal to

JavaScript Logical Operators:

&& logical and
|| logical or
! logical not

JavaScript Arithmetic Operators:

+ Addition
– Subtraction
* Multiplication
/ Division
% Modulus (Remainder)
++ Increment

 

JavaScript if else Condition:
JavaScript includes if-else conditional statements to control the program flow.

Syntax:

if(condition expression)
{
//Execute this code..
}
else{
//Execute this code..
}

Example:
<html>
<body>
<h1>Javascript If condition</h1>
<script>

var k = 30;

if( k > 18 )
{
document.write(“Value of k=”+k);
document.write(“<br><b>Qualifies for next exam</b>”);
}

</script>

</body>
</html>

2.

<html>
<body>
<h1>Javascript If else condition</h1>
<script>

var k = prompt(“Enter a value”);

if( k >= 30 )
{
document.write(“Value of k=”+k);
document.write(“<br><b>Qualifies for next exam</b>”);
}

else

{
document.write(“Value of k=”+k);
document.write(“<br><b>Sorry for not passing</b>”);
}
</script>

</body>
</html>

Switch statement:
The switch is a conditional statement like if statement. Switch is useful when you want to execute

one of the multiple code blocks based on the return value of a specified expression.

Example:

<html>
<body>
<h1 align=”center”> <u> Switch Statement </u> </h1>
</body>
<script>
var x = parseInt(prompt(“Choose 1 or 2 or 3”))
switch(x)
{
case 1 : document.write(“You choose 1”)
break

case 2 : document.write(“You choose 2”)
break

case 3 : document.write(“You choose 3”)
break

default:
document.write(“wrong switch”)
}
</script>
</html>

Click here

Share this page :