0% found this document useful (0 votes)
28 views6 pages

Exp 4

JavaScript

Uploaded by

MOHD SHOEB TAJ
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)
28 views6 pages

Exp 4

JavaScript

Uploaded by

MOHD SHOEB TAJ
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

JavaScript has three kind of popup boxes: Alert box, Confirm box, and Prompt box.

Alert Box

An alert box is often used if you want to make sure information comes through to the user.

When an alert box pops up, the user will have to click "OK" to proceed.

Syntax
alert("sometext");

Confirm Box

A confirm box is often used if you want the user to verify or accept something.

When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed.

If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false.

confirm("sometext");

Prompt Box

A prompt box is often used if you want the user to input a value before entering a page.

When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed
after entering an input value.

If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box
returns null.

prompt("sometext","defaultText");
a) Input: Click on Display Date button using onclick( ) function Output: Display
date in the textbox

<html>

<body bgcolor="#ACC8E6">

<title>DATE</title>

<script>

function display()

var x="you have clicked";

var d=new Date();

var date=d.getDate();

var month=d.getMonth();

month++;

var year=d.getFullYear()

document.getElementById("dis").value=date+"/"+month+"/"+year;

</script>

<form>

<center> <br>

<h1>Click on the button to see today's Date"</h1> <br>

<input type="text" id="dis"/><br/> <br>

<input type="button" value="Display Date" onclick="display()"/>

</center>

</form>

</body>

</html>
b) Input: A number n obtained using prompt Output: Factorial of n number using alert

<html>

<head>

<title>

Factorial

</title>

</head>

<script language='javascript'>

function factorialcalc()

number=parseInt(prompt("enter a number","Enter whole number"))

let factorial = 1

for(i=1;i<=number;i++)

factorial=factorial*i

alert("the factorial of "+number+" is "+factorial)

</script>

<body>

<form name="form">

<input type="button" value="Factorial" onclick='factorialcalc()'/>

</form>

</body>

</html>
c) Input: A number n obtained using prompt Output: A multiplication table of numbers
from 1 to 10 of n using alert
<html>

<head>

<title> Multiplication Table </title>

</head>

<body>

<script type="text/javascript">

var n=prompt("Enter positive value for n: "," ");

if(!isNaN(n))

var table="";

var number="";

for(i=1;i<=10;i++)

number = n * i;

table += n + " * " + i + ""+ number + "\n";

alert(table);

else

alert("Enter positive value");

n=prompt("Enter positive value for n: "," ");

document.write(n+" table values displayed using alert ..<br />");

</script>
</body> </html>

d) Input: A number n obtained using prompt and add another


number using confirm Output:
Sum of the entire n numbers using alert.

<html>

<head>

<title>sum of n numbers using popup boxes</title>

<script language='javascript'>

function addsum()

alert("Enter a list of numbers.");

var keepgoing = true

var sumofnums = 0

while (keepgoing)

sumofnums = sumofnums + parseInt(prompt("what's the next number to add?",""));

keepgoing = confirm("add another number?")

alert("the sum of all your numbers is "+ sumofnums)

</script>

</head>

<body>

<form name=frm>

<input type=button value='sum of n numbers' onclick='addsum()'/>

</form>

</body>
</html>

You might also like