JavaScript Practice
1. Program to display the string “Hello World”
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
[Link]("hellow world");
</script>
<body>
</html>
2. Program to display the value of variable a.
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
var a=10;
[Link](a);
</script>
<body>
</html>
3. Program to sum the value of two variables
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
var a=10;
var b=10
[Link](a+b);
</script>
<body>
</html>
4. Program to display the sum, difference, product and division of two
variables.
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
var a=10;
var b=10;
[Link]("the sum=",a+b);
[Link]("<br>the difference=",a-b);
[Link]("<br>the product=",a*b);
[Link]("<br>the division=",a/b);
</script>
<body>
</html>
5. Program to input the number form user and display on the screen.
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
var a=prompt("Enter the number:");
[Link](a);
</script>
<body>
</html>
6. Program to input two numbers from user and display on the screen.
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
var a=prompt("Enter the first number:", "number");
var b=prompt("Enter the second number:");
[Link](a);
[Link](b);
</script>
<body>
</html>
7. Program to input the first name and last name from the user and display on
the screen.
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
var a=prompt("Enter the First Name:","FIRST NAME");
var b=prompt("Enter the Last Name:", "LAST NAME");
[Link](a);
[Link](b);
</script>
<body>
</html>
8. Program to check whether the input number is equal or not.
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
var a=prompt("Enter the number:");
if(a==10)
[Link]("you entered:"+a);
</script>
<body>
</html>
9. Program to check whether the given number is right or wrong.
html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
var a=prompt("Enter the number:");
if(a==10)
[Link]("right number:");
else
[Link]("wrong number:");
</script>
<body>
</html>
[Link] to find out whether the given number is odd or even.
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
var a=prompt("Enter the number:");
if(a%2==0)
[Link]("Even number:");
else
[Link]("Odd number:");
</script>
<body>
</html>
[Link] to check the age of the voter is eligible or not to vote.
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
var a=prompt("Enter the age:");
if(a>=18)
[Link]("Eligible");
else
[Link]("Not eligible");
</script>
<body>
</html>
[Link] to input the percentage and display the division.
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
var a=prompt("enter the percentage:", "number")
if(a>=80)
[Link]("distinction");
else if(a>=60)
[Link]("First");
else if(a>=50)
[Link]("second");
else if(a>=40)
[Link]("third");
else
[Link]("fail");
</script>
<body>
</html>
13. Program to find the greatest number among 2 numbers.
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
var a=prompt("enter the percentage:", "number");
var b=prompt("enter the percentage:", "number");
if(a>b)
[Link]("a is greater");
else
[Link]("b is greater");
</script>
<body>
</html>
14. Program to find the greatest number among three numbers.
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
var a=prompt("enter the number");
var b=prompt("enter the number");
var c=prompt("enter the number");
if(a>b)
if(a>c)
[Link]("a is greater");
else
[Link]("c is greater");
else
if(b>c)
[Link]("b is greater");
else
[Link]("c is greater");
</script>
<body>
</html>
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
var day=2;
switch(day)
case 1:
[Link]("sunday");
break;
case 1:
[Link]("sunday");
break;
case 2:
[Link]("monday");
break;
case 3;
[Link]("Tuesday");
break;
case 4:
[Link]("Wednesday");
break;
case 5:
[Link]("Thursday");
break;
case 6:
[Link]("Friday");
break;
case 7:
[Link]("Sataurday");
break;
default:
[Link]("Invalid number");
</script>
</body>
</html>
USING FOR LOOP
15. Program to display the number from 0 to 4.
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
for(i=0; i<5; i++)
{
[Link](i);
}
</script>
</body>
</html>
Output: 01234
16. Program to display the number from 0 to 4 in vertical manner.
<html>
<head>
<title>javascript</title>
</head>
<body>
<script type="text/javascript">
for(i=0; i<5; i++)
{
[Link](i+ "<br>");
}
</script>
</body>
</html>