0% found this document useful (0 votes)
7 views3 pages

Wip Unit 2 Program

The document contains three JavaScript examples: the first script finds and displays prime numbers between 1 and 100, the second calculates the factorial of a user-input number, and the third shows a welcome message in an alert when a button is clicked. Each example is embedded within HTML structure for execution in a web browser. The scripts demonstrate basic programming concepts and user interaction in JavaScript.

Uploaded by

priya j
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)
7 views3 pages

Wip Unit 2 Program

The document contains three JavaScript examples: the first script finds and displays prime numbers between 1 and 100, the second calculates the factorial of a user-input number, and the third shows a welcome message in an alert when a button is clicked. Each example is embedded within HTML structure for execution in a web browser. The scripts demonstrate basic programming concepts and user interaction in JavaScript.

Uploaded by

priya j
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/ 3

1)Java script to find the Prime number between 1 and 100

<html>

<body>

<script>

var a,b;

for(a=2;a<100;a++)

var c=true;

for (b=2;b<a;b++)

if(a%b==0)

c=false;

break;

if(c)

document.write(a+' ,');

}}

</script>

</body>

</html>

Output:
2) Write a Java Script to find factorial of a given number

<html>

<body>

<script>

var n = prompt("Enter any number: ");

var i, fact=1;

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

fact= fact*i;

document.write("factorial is: " + fact);

</script>

</body>

</html>

Output:

3) Demonstrate a java script to display the welcome message using the alert whenever button
of a html form is pressed.

<html>

<head>
<script type = "text/javascript">

function fun() {

alert ("welcome");

</script>

</head>

<body>

<p> Click the following button to see the effect </p>

<form>

<input type = "button" value = "Click me" onclick = "fun();" />

</form>

</body>

</html>

Output:

You might also like