demonstrate the calculator program.
Program :
<html>
<body> <script>
const operator = prompt('Enter operator to perfome the calculation(either+,-,* or/):');
const number1 = parseFloat(prompt('Enter the first number:'));
const number2 = parseFloat(prompt('Enter the second number:'));
let result;
if(operator =='+')
{
result = number1+number2;
}
else if(operator =='-')
{ result = number1-number2;
}
else if(operator =='*')
{ result = number1*number2;
} else
{
result=number1/number2;
}
window.alert("Result is"+result);
</script>
</body>
</html>
OUTPUT :
Result :
The given program is executed successfully.
Ex no : 2 Date :
FACTORIAL
Aim:
To demonstrate the factorial program.
Program :
<html>
<body style="text align:center;font-size:20px;">
<h1>welcome to department of BCA</h1> <h1>FACTORIAL NUMBER</h1>
enter the number:<input id="num">
<br><br>
<button onclick="fact()">factorial</button>
<p id="res"></p> <script> function fact()
{ var i,num,f; f=1;
num=document.getElementById("num").value; for(i=1;i<=num;i++)
{ f=f*i;
document.getElementById("res").innerHTML="the factorial of the number"+ i +"is:" +f;
}
}
</script>
</body>
</html>
Output :
Result :
The given program is executed successfully…
Ex no : 3 Date :
FIBONACCI SERIES
Aim:
To demonstrate the fibonacci program.
Program :
<html>
<head>
<title>Fibonacci Series in Javascript</title>
</head>
<body> <script>
var n1 = 0, n2 = 1, next_num, i;
var num=parseInt(prompt("Enter the limit for Fibonacci Series"));
document.write("Fibonacci series:"); for(i=1;i<=num;i++)
{
document.write(" <br> " + n1); next_num=n1+n2; n1=n2; n2=next_num;
}
</script>
</body>
</html>
OUTPUT:
Result :
The given program is executed successfully…
Ex no : 4 Date :
PRIME NUMBER
Aim:
To demonstrate the prime number program.
Program :
<html >
<head>
<title>Prime Numbers between 1 and 100</title>
</head>
<body>
<h1>Prime Numbers between 1 and 100</h1>
<ul id="primeList"></ul>
<script> function isPrime(num)
{ if (num <= 1) return false; if (num <= 3) return true;
if (num % 2 === 0 || num % 3 === 0) return false;
for (let i = 5; i * i <= num; i += 6)
{
if (num % i === 0 || num % (i + 2) === 0) return false; } return true; }
function displayPrimesInRange(start, end)
{
let primeList = document.getElementById("primeList"); for (let i = start; i <= end; i++)
{ if (isPrime(i)) {
let listItem = document.createElement("li"); listItem.textContent = i; primeList.appendChild(listItem);
}
}
}
displayPrimesInRange(1, 100);
</script>
</body>
</html>
OUTPUT:
Result :
The given program is executed successfully…
FORMATTING TAG
To the Formatting tags program.
Program :
<html>
<head>
<title>Text Formatting</title>
<style> body
{ text-align: center;
}
</style>
</head>
<body>
<h3><u>Text Formatting</u></h3>
The text is <p>paragraph</p><br>
The text is <pre>pre formatting</pre><br>
The text is <b>Bold</b><br>
The text is <i>Italic</i><br>
The text is <u>Underline</u><br>
The text is <big>Big</big><br>
The text is <small>small</small><br> The text is <em>Emphasis</em><br> The text is <strike>strike</strike><br>
Result
😅
SUM OF DIGITS
To the sum of digit program.
Program :
<html>
<head>
<title>Sum of Digits</title>
</head>
<body>
<h2>Sum of Digits Calculator</h2>
<input type="text" id="numberInput" placeholder="Enter a number">
<button onclick="calculateSum()">Calculate</button>
<p id="result"></p> <script> function calculateSum()
{
let inputNumber = document.getElementById("numberInput").value; let sum = 0;
for (let digit of inputNumber) { sum += parseInt(digit) || 0;
}
document.getElementById("result").textContent = "Sum of digits: " + sum;
}
</script>
</body>
</html>
Output :
MAPS
To an accept a number from the user and display the number of words in it program. (Do not use split() function).
Program :
<html>
<body>
<h2>Image Maps</h2>
<p>Click on the computer, the phone, or the cup of coffee to go to a new page and read more about the topic:</p>
<img src="file:///D:/kayal/workplace.jpg" alt="Workplace" usemap="#workmap" width="400" height="379">
<map name="workmap">
<area shape="rect" coords="34,44,270,350" alt="Computer" href="file:///D:/kayal/mac.jpg">
<area shape="rect" coords="290,172,333,250" alt="Phone" href="file:///D:/kayal/cellphone.jpg">
<area shape="circle" coords="337,300,44" alt="Cup of coffee" href="file:///D:/kayal/coffeehouse2.jpg">
</map>
</body>
</html>
LINKS
To design a web pages with links to different pages and allow navigation b/w web pages.
Program :
<html>
<head>
<title>Navigation Example</title>
</head>
<body>
<header>
<h1>Welcome to My Website</h1>
</header>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
</ul>
</nav>
<main>
<h2>Home Page</h2>
<p>Welcome to our website. This is the home page.</p>
</main>
</body>
</html>
Output :
Comments
Post a Comment