CSS - Practical 2
CSS - Practical 2
Q2. Write a program to check whether the entered character is a vowel or not.
Code:-
<html>
<head>
<title>Anas Qureshi-220440</title>
<script>
let str=prompt("Enter a character to check wheather enter character is vowel or not")
if(str=='A'||str=='a'||str=='E'||str=='e'||str=='I'||str=='i'||str=='O'||str=='o'||str=='U'||str=='u'){
alert(str+" is a vowel")
}
else{
alert(str+" is not a vowel")
}
</script>
</head>
<body>
</body>
</html>
Output:-
Q3. Write a program to print the odd number between 1 to 20 using while loop
Code:-
<html>
<head>
<title>Anas Qureshi-220440</title>
<script>
for(let i=0;i<=20;i++){
if(i%2!=0){
document.write(i+"\n")
}
}
</script>
</head>
<body>
</body>
</html>
Output:-
Q4. Write a menu driven program for addition and subtraction until the user wanted to continue
using do while loop.
Code:-
<html>
<head>
<title>Anas Qureshi-220440</title>
<script>
do {
choice = parseInt(prompt("Select an option:\n1. Addition\n2. Subtraction\n3. Exit\nEnter your
choice: "))
let num1, num2
switch (choice) {
case 1:
num1 = Number.parseInt(prompt("Enter the number 1"))
num2 = Number.parseInt(prompt("Enter the number 2"))
alert("Addition of " + num1 + " and " + num2 + " = " + (num1 + num2))
break;
case 2:
num1 = Number.parseInt(prompt("Enter the number 1"))
num2 = Number.parseInt(prompt("Enter the number 2"))
alert("Subtraction of " + num1 + " and " + num2 + " = " + (num1 - num2))
break;
case 3:
alert("Exiting the program.");
break;
default:
alert("Invalid choice. Please try again.");
}
} while (choice !== 3);
</script>
</head>
<body>
</body>
</html>
Output:-