[Go to site: main page, start]

100% found this document useful (1 vote)
20 views7 pages

JavaScript Programming Examples

The document contains multiple HTML and JavaScript code snippets demonstrating various programming tasks. These include printing numbers from 1 to 10, checking if a number is even or odd, determining if a number is a palindrome, generating a Fibonacci series, printing a specific pattern, and creating an addition program with user input. Each section includes the code and expected output for clarity.

Uploaded by

ayushmangukiya2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
20 views7 pages

JavaScript Programming Examples

The document contains multiple HTML and JavaScript code snippets demonstrating various programming tasks. These include printing numbers from 1 to 10, checking if a number is even or odd, determining if a number is a palindrome, generating a Fibonacci series, printing a specific pattern, and creating an addition program with user input. Each section includes the code and expected output for clarity.

Uploaded by

ayushmangukiya2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1) Write a program to print 1 t0 10 using for loop.

<html>

<head>

<title>FOR LOOP</title>

</head>

<body>

<script type="text/javascript">

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

[Link](i + "<br>");

</script>

</body>

</html>

Output:

10
2) Check number is even or odd.

<html>

<head>

<title></title>

</head>

<body>

<script>

let input = prompt("Enter a number:");

let number = parseInt(input);

if (number % 2 === 0) {

[Link](" is even.");

} else

[Link](" is odd.");

</script>

</body>

</html>

OUTPUT:

ENTER ANY NUMBER: 4

Number is even.
3) Write a number palindrome or not.

<html>

<head>

<title>Palindrome or not</title>

</head>

<body>

<script>

let num = prompt("enter number:");

let reverse = [Link]('').reverse().join('');

if (num ==reverse) {

[Link]("palidrome");

} else {

[Link]("not palidrome");

</script>

</body>

</html>

Output:

Enter number: 121

Palindrome

Enter number: 110

Not Palindrome
4) Write JavaScript program to print Fibonacci series.

<html>

<head>

<title>Fibonacci series</title>

</head>

<body>

<script>

let n = prompt("Enter number");

n = parseInt(n);

let a = 0, b = 1;

[Link]("Fibonacci series:");

for (let i = 0; i < n; i++) {

[Link](a,"<br>");

let next = a + b;
a = b;
b = next;
}
</script>

</body>

</html>

OUTPUT:

Enter number: 7

0 1 1 2 3 5 8
5) Print following pattern.

A
AB
ABC
ABCD
ABCDE

<html>
<head>
<title>Triangle</title>
</head>
<body>
<script>

for(let i=0; i<=4; i++){

for(let j=0; j<=i; j++)

[Link]([Link](65 + j) + " ");

[Link]("<br>");

</script>

</body>

</html>
6) Create Addition Program Using Following Design:

<html>

<head>

</head>

<body>

<form>

<label > Enter Number 1: </label>

<input type="Number" name="num1" id="num1"> <br>

<label> Enter Number 2: </label>

<input type="Number" name="num2" id="num2"> <br>

<button type="button" > clickme </button>


<p>Result: <span id="result">0</span></p>

<script >

function addnum(){

let a=parseInt([Link]("num1").value);

let b=parseInt([Link]("num2").value);

let sum=a+b;

//[Link](sum);

[Link]("result").innerText = sum;

</script>

</body>

</form>

</html>

You might also like