0% found this document useful (0 votes)
6 views

CSS - Practical 2

Uploaded by

anasqureshi6556
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

CSS - Practical 2

Uploaded by

anasqureshi6556
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

CSS- PRACTICAL 2

Name:- Anas Qureshi


Roll No:- 220440
---------------------------------------------------------------------------------------------------------------------------
Q1. Write a program to print the greatest of three number using if else ladder.
Code: -
<html>
<head>
<title>Anas Qureshi-220440</title>
<script>
let num1=Number.parseFloat(prompt("Enter the number 1"))
let num2=Number.parseFloat(prompt("Enter the number 2"))
let num3=Number.parseFloat(prompt("Enter the number 3"))
if(num1>num2){
if(num1>num3){
alert(num1+" is the greatest of all three number")
}
}
else if(num2>num3){
alert(num2+" is the greatest of all three number")
}
else{
alert(num3+" is the greatest of all three number")
}
</script>
</head>
<body>
</body>
</html>
Output: -

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:-

Q5. Write a program to print the right-angle triangle.


Code:-
<html>
<head>
<title>Anas Qureshi-220440</title>
<script>
let rows = parseInt(prompt("Enter the number of rows for the triangle: "));
for (let i = 1; i <= rows; i++) {
for (let j = 1; j <= i; j++) {
document.write("*")
}
document.write( '<br>')
}
</script>
</head>
<body>
</body>
</html>
Output:-

You might also like