0% found this document useful (0 votes)
5 views7 pages

JavaScript Programming Examples

The document contains a series of HTML programs demonstrating various JavaScript concepts, including variables, arithmetic operations, functions, conditional statements, loops, and user input. Each program is structured to showcase a specific feature or functionality of JavaScript, such as calculating sums, determining even or odd numbers, and handling user interactions. Overall, it serves as an educational resource for learning basic JavaScript programming through practical examples.

Uploaded by

pritamikhe
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)
5 views7 pages

JavaScript Programming Examples

The document contains a series of HTML programs demonstrating various JavaScript concepts, including variables, arithmetic operations, functions, conditional statements, loops, and user input. Each program is structured to showcase a specific feature or functionality of JavaScript, such as calculating sums, determining even or odd numbers, and handling user interactions. Overall, it serves as an educational resource for learning basic JavaScript programming through practical examples.

Uploaded by

pritamikhe
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

Program no 01

<html>
<body>

<h2>My First Web Page</h2>


<p>My first paragraph.</p>

<button type="button" onclick="document. Write(5 + 6)">Try it</button>

</body>
</html>

Program no 02
<html>
<body>

<h2>JavaScript Statements</h2>

<p>Multiple statements on one line are allowed. </p>

<p id="demo1"></p>

<script>
let a, b, c;
a = 5; b = 6; c = a + b;
document. getElementById("demo1"). innerHTML = c;
</script>

</body>
</html>

Program no 03
<html>
<body>
<h1>JavaScript Variables</h1>

<p>In this example, x, y, and z are variables. </p>

<p id="demo"></p>

<script>
var x = 5;
var y = 6;
var z = x + y;
document. getElementById("demo"). innerHTML =
"The value of z is: " + z;
</script>
</body>
</html>

Program no – 04
<html>
<body>

<h1>JavaScript Arithmetic</h1>
<h2>The * Operator</h2>

<p id="demo"></p>

<script>
let x = 5;
let y = 2;
let z = x * y;
document. getElementById("demo"). innerHTML = z;
</script>

</body>
</html>
Program no – 05
<html>
<body>

<h1>JavaScript Assignments</h1>
<h2>Remainder Assignment</h2>
<h3>The %= Operator</h3>

<p id="demo"></p>

<script>
let x = 10;
x %= 5;
document. getElementById("demo"). innerHTML = "Value of x is: " + x;
</script>

</body>
</html>

Program no 06

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Functions</h1>

<p>Call a function which performs a calculation and returns the result:</p>

<p id="demo"></p>
<script>
function myFunction(p1, p2) {
return p1 * p2;
}

let result = myFunction(4, 3);


document. getElementById("demo"). innerHTML = result;
</script>

</body>
</html>
Program no 07

<html>
<body>

<h2>JavaScript if</h2>

<p>Display "Good day!" if the hour is less than 18:00:</p>

<p id="demo">Good Evening! </p>

<script>
if (new Date (). getHours() < 18) {
document. getElementById("demo"). innerHTML = "Good day!";
}
</script>

</body>
</html>

Program No – 08

<html>
<body>

<h2>JavaScript switch</h2>
<p id="demo"></p>
<script>
let day;
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}
document. getElementById("demo"). innerHTML = "Today is " + day;
</script>

</body>
</html>

Program No – 9
<html>
<head>
<title>for loop</title>
</head>
<body>
<h2> Numbers are</h2><br>
<script type="text/javascript">
var a;
for(a=1;a<=10;a++)
{
document. write(a+"<br>");
}
</script>
</body>
</html>

Program no -11

<html>
<head>
<title>even or odd</title>
</head>
<body>
<h2>Find Even or Odd Number</h2><br>
<script type="text/javascript">
var i=23;
if(i%2==0)
{
document. write ("no is even");
}
else
{
document. write ("no is odd");
}
</script>
</body>
</html>
Program no 12

<html>
<head>
<title>odd & Even</title>
</head>
<body>
<script type="text/javascript">
var a;
for(a=1;a<=20;a++)
{
if(a%2==0)
{
[Link](a+"<br>");
}
}
</script>
</body>
</html>

Program no - 13
<html>
<head>
<title>Leap Year</title>
</head>
<body>
<script type="text/javascript">
var a;
a=prompt ("Enter Year");
if(a%4==0)
{
alert ("Year Is Leap Year");
}
else
{
alert ("Year Is Not Leap Year");
}
</script>
</body>
</html>

Program no – 14

<html>
<head>
<script type="text/javascript">
function msg(){
alert("Hello Javatpoint");
}
</script>
</head>
<body>
<p>Welcome to JavaScript</p>
<form>
<input type="button" value="click" onclick="msg()"/>
</form>
</body>
</html>

Program no -15
<html>
<body>
<script>
var a=10;
var b=20;
var c=a+b;//It adds values of a and b variable
[Link](c);//prints sum of 10 and 20
</script>
</body>
</html>

Program no- 16
<html>
<body>
<script>
var a=20;
if(a>10){
[Link]("value of a is greater than 10");
}
</script>
</body>
</html>

Program – 17
<html>
<body>
<script>
function getcube(number)
{
alert(number*number*number);
}
</script>
<form>
<input type="button" value="click" onclick="getcube(4)"/>
</form>
</body>
</html>

You might also like