Write a program to show use of alert, confirm and prompt box.
1) Alert Box
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Practical-12</title>
</head>
<body>
<Script>
//Alert Example
alert("This is alert box!");
// alert(100);
// var a = 10;
// var b = 20;
// alert(a + b);
</Script>
</body>
</html>
Output:
2)Confirm Box
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Practical-12</title>
</head>
<body>
<Script>
//Confirm Example
var message;
if (confirm("Do you want to save changes?") == true) {
message = "Data saved successfully!";
} else {
message = "Save Cancelled!"
}
console.log(message);
</Script>
</body>
</html>
Output:
3) Prompt Box
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Practical-12</title>
</head>
<body>
<Script>
//Prompt Example
var input = prompt("Please enter your name: ", "Name");
if (input != null) {
alert("You Name is " + input);
}
</Script>
</body>
</html>
Output:
a) Ask user to input some week day. match it with actual
current week day(use dateObject to get the current week
day). if both values matches display a message "HIT" else
display a message "MISSED".
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Practical-12</title>
</head>
<body>
<Script>
//Ask user to input some week day.match it with actual current week day(use dateobject to get the current week day).if both values matches display a message "hit" else display a message "missed".
var weekDay = prompt("Enter any Week Day like 1,2,3...");
var day = new Date();
if (weekDay == day.getDay()) {
alert("HIT");
} else {
alert("MISSED")
}
</Script>
</body>
</html>
Output:
b) Calculate the BMI of a user by asking him for his weight
(Kilograms) & Height Meters. formula:- BMI=m/h^2.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Practical-12</title>
</head>
<body>
<Script>
//Calculate the BMI of a user by asking him for his weight(kilograms) & Height Meters.Formula:-BMI=m/h^2.
var weight = prompt("Enter the weight of your body in kg");
var height = prompt("Enter the height of your body in meter");
var bmi = weight / Math.pow(height, 2);
alert("Your BMI is: " + bmi);
</Script>
</body>
</html>
Output:
All Code :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Practical-12</title>
</head>
<body>
<script>
//Alert Example
// alert("This is alert box!");
// alert(100);
// var a = 10;
// var b = 20;
// alert(a + b);
//Confirm Example
// var message;
// if (confirm("Do you want to save changes?") == true) {
// message = "Data saved successfully!";
// } else {
// message = "Save Cancelled!"
// }
// console.log(message);
//Prompt Example
// var input = prompt("Please enter your name: ", "Name");
// if (input != null) {
// alert("You Name is " + input);
// }
//Ask user to input some week day.match it with actual current week day(use dateobject to get the current week day).if both values matches display a message "hit" else display a message "missed".
// var weekDay = prompt("Enter any Week Day like 1,2,3...");
// var day = new Date();
// if (weekDay == day.getDay()) {
// alert("HIT");
// } else {
// alert("MISSED")
// }
//Calculate the BMI of a user by asking him for his weight(kilograms) & Height Meters.Formula:-BMI=m/h^2.
var weight = prompt("Enter the weight of your body in kg");
var height = prompt("Enter the height of your body in meter");
var bmi = weight / Math.pow(height, 2);
alert("Your BMI is: " + bmi);
</script>
</body>
</html>
Comments
Post a Comment