You are on page 1of 3

JS2 yug Khanna XIB

1. WAP to accept age and display "you can vote" if age is 18


and above otherwise display "you can’t vote"
Ans:<script>
var age = parseInt(prompt("Enter your age"));
if (age>=18)
{document.write("You are eligible to vote");}
else
{document.write("You are not eligible to vote");}
</script>
2. WAP to accept a number and check whether it is divisible
by 5 or not
Ans:<script>
var x = parseInt(prompt("Enter a number"));
if (x % 5 == 0)
{document.write("This number is divisible by 5");}
else
{document.write("This number is not divisible by 5");}
</script>
3. WAP to accept a number and check whether it’s even or
odd.
Ans:<script>
var x = parseInt(prompt("Enter a number"));
if (x % 2 == 0)
{document.write("This number is even");}
else
{document.write("This number is odd");}
</script>
4. WAP to accept 2 numbers and display the highest no.
JS2 yug Khanna XIB
Ans:<script>
var x = parseInt(prompt("Enter a number"));
var y = parseInt(prompt("Enter another number"));
if (x > y)
{document.write("The highest number is " + x);}
else
{document.write("The highest number is " + y);}
</script>
5. WAP to accept 3 numbers and display highest
Ans:<script>
var x = parseInt(prompt("Enter first number"));
var y = parseInt(prompt("Enter second number"));
var z = parseInt(prompt("Enter third number"));
if (x>y)
if (x>z)
{document.write("The highest number is " + x);}
else
{document.write("The highest number is " + z);}
else if (y>z)
{document.write("The highest number is " + y);}
else
{document.write("The highest number is " + z);}
</script>
6. WAP to accept a year and display whether it is a leap year
or not
Ans:<script>
var y = parseInt(prompt("Enter a year"));
JS2 yug Khanna XIB
if (y % 4 == 0)
{document.write("The year is a leap year");}
else
{document.write("The year is not a leap year");}
</script>
7. WAP to accept aggregate percentage and display the
message as per following table
Marks Message
85 - 100 Excellent
70 - 85 Good
50 - 70 Fair
35 - 50 Need to improve
Below 35 Fail
Ans:<script>
var p = parseInt(prompt("Enter your aggregate percentage"));
if (p>100)
{document.write("Please enter percentage below 100");}
else if (p>=85)
{document.write("Excellent");}
else if (p>=70)
{document.write("Good");}
else if (p>=50)
{document.write("Fair");}
else if (p>=35)
{document.write("Need to improve");}
else
{document.write("Fail");}
</script>

You might also like