Java Script


JavaScript Tutorial


Admission Enquiry Form


Print corresponding week day of the number taken using if else if

Example:

<html>
<head>
<title>corresponding week days using if else if</title>
</head>

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

if(num==1)
{
document.write("Monday");
}
else if(num==2)
{
document.write("Tuesday");
}
else if(num==3)
{
document.write("Wednesday");
}
else if(num==4)
{
document.write("Thursday");
}
else if(num==5)
{
document.write("Friday");
}
else if(num==6)
{
document.write("Saturday");
}
else if(num==7)
{
document.write("Sunday");
}

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


Print corresponding week day of the number entered in prompt using if else if

Example:

<html>
<head>
<title>corresponding week day using prompt() function in if else if</title>
</head>

<body>
<script>
var num;
num=parseInt(prompt("Enter day in number from 1 to 7"));
if(num==1)
{
document.write("Monday");
}
else if(num==2)
{
document.write("Tuesday");
}
else if(num==3)
{
document.write("Wednesday");
}
else if(num==4)
{
document.write("Thursday");
}
else if(num==5)
{
document.write("Friday");
}
else if(num==6)
{
document.write("Saturday");
}
else if(num==7)
{
document.write("Sunday");
}

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



Print corresponding week day of the number entered in if else if on Button click using function

Example:

<html>
<head>
<title>corresponding week day on button click using function in if else if</title>
<script>
function week_days()
{
var num;
num=parseInt(prompt("Enter day in number from 1 to 7"));
if(num==1)
{
document.write("Monday");
}
else if(num==2)
{
document.write("Tuesday");
}
else if(num==3)
{
document.write("Wednesday");
}
else if(num==4)
{
document.write("Thursday");
}
else if(num==5)
{
document.write("Friday");
}
else if(num==6)
{
document.write("Saturday");
}
else if(num==7)
{
document.write("Sunday");
}
}//end of function
</script>
</head>

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