Java Script


JavaScript Tutorial


Admission Enquiry Form


Get corresponding Ice cream of the number taken using if else if.

Example:

<html>
<head>
<title>icecream according to choice using if else if</title>
</head>

<body>
<script>
var num;
num=2;

if(num==1)
{
document.write("Butterscotch");
}
else if(num==2)
{
document.write("Chocolate");
}
else if(num==3)
{
document.write("Vanilla");
}
else if(num==4)
{
document.write("Strawberry");
}

</script>
</body>
</html>



Get corresponding Ice cream of the number entered in if else if using prompt() function.

Example:

<html>
<head>
<title>icecream according to choice entered using prompt() in if else if</title>
</head>

<body>
<script>
var num;
num=parseInt(prompt(" Enter 1 for Butterscotch \n Enter 2 for Chocalate \n Enter 3 for vanilla \n Enter 4 for strawberry"));

if(num==1)
{
document.write("Butterscotch");
}
else if(num==2)
{
document.write("Chocolate");
}
else if(num==3)
{
document.write("Vanilla");
}
else if(num==4)
{
document.write("Strawberry");
}

</script>
</body>
</html>


Get corresponding Ice cream of the number entered in if else if on Button click using function.

Example:

<html>
<head>
<title>icecream according to choice entered using function in if else if</title>
<script>
function get_icecream()
{
var num;
num=parseInt(prompt(" Enter 1 for Butterscotch \n Enter 2 for Chocalate \n Enter 3 for vanilla \n Enter 4 for strawberry"));

if(num==1)
{
document.write("Butterscotch");
}
else if(num==2)
{
document.write("Chocolate");
}
else if(num==3)
{
document.write("Vanilla");
}
else if(num==4)
{
document.write("Strawberry");
}

}// end of function
</script>

</head>

<body>
<input type="button" value="click" onClick="get_icecream()">
</body>
</html>