WT Week 5 H6
WT Week 5 H6
Problem statements
1 Write an HTML program including any required Javascript , when the button named “CLICK
HERE” is clicked then Paragaraph content should be changed.
2 Write a Javascript program to turn on the light and turn off the light.
3 Write an HTML program including any required Javascript to find maximum of three numbers
using functions
4 Write an HTML program including any required Javascript to find sum of individual digits.
5 Write an HTML program including any required JavaScript that receives an integer in one text
field, and check whether the number is palindrome or not, when the button named
“palindrome” is clicked.
6 Write an HTML program including any required Javascript that receives an integer in one text
field, and check whether the number is prime or not, when the button named “Prime” is
clicked
1. Write an HTML program including any required Javascript , when the button named “CLICK HERE” is
clicked then Paragaraph content should be changed.
PROGRAM CODE:
<html>
<head><title>Paragraph</title></head>
<body>
<p id="abc">JavaScript is a lightweight interpreted programming language </p>
<input type="button" value="CLICK HERE" onclick="document.getElementById('abc').innerHTML ='It
can be used for both Client-side as well as Server-side developments'">
</body>
</html>
OUTPUT:
2.Write a Javascript program to turn on the light and turn off the light
PROGRAMCODE:
<html>
<head><title>Lights</title></head>
<body>
<img id="abc" src="https://www.livehome3d.com/assets/img/articles/comparinglightbulbtypes/
[email protected]" alt="Light" width="200" height"200"><br><br>
<input type="button" value="Light ON"
onclick="document.getElementById('abc').src='https://cdn.mos.cms.futurecdn.net/
HaPnm6P7TZhPQGGUxtDjAg-320-80.jpg'" width="200" height"200">
<input type="button" value="Light OFF"
onclick="document.getElementById('abc').src='https://www.livehome3d.com/assets/img/articles/
comparinglightbulbtypes/[email protected]'">
</body>
</html>
OUTPUT:
3. Write an HTML program including any required Javascript to find maximum of three numbers using
functions
PROGRAM CODE:
<html>
<head><title>Max</title></head>
<body>
<h2>Maximum of three numbers</h2>
<input type="button" value="Result" onclick="myfun()">
<p id="a"></p>
<script>
function myfun()
{
var a=prompt("Enter a value");
var b=prompt("Enter b value");
var c=prompt("Enter c value");
if(a>b && a>c){
document.getElementById('a').innerHTML="Maximum of three numbers is "+a;
}
else if(b>a && b>c){
document.getElementById('a').innerHTML="Maximum of three numbers is "+b;
}
else {
document.getElementById('a').innerHTML="Maximum of three numbers is "+c;
}
}
</script>
</body>
</html>
OUTPUT:
4.Write an HTML program including any required Javascript to find sum of individual digits.
PROGRAM CODE:
<html>
<head><title>Sum of digits</title></head>
<body>
<h3>Sum of digits</h3>
<input type="button" value="Result" onclick="myfunction()">
<p id="a"></p>
<script>
function myfunction()
{
var n=prompt("Enter n value");
var sum=0,rem;
while(n>0)
{
rem=n%10;
sum=sum+rem;
n=parseInt(n/10);
}
document.getElementById("a").innerHTML="Sum of digits is "+ sum;
}
</script>
</body>
</html>
OUTPUT:
5. Write an HTML program including any required JavaScript that receives an integer in one text field,
and check whether the number is palindrome or not, when the button named “palindrome” is clicked
PROGRAM CODE:
<html>
<head><title>Palindrome</title></head>
<body>
<h3>Palindrome</h3>
<input type="button" value="Palindrome" onclick="myfunction()">
<p id="a"></p>
<script>
function myfunction()
{
var n=prompt("Enter n value");
var sum=0,rev;
temp=n;
while(n>0)
{
rev=n%10;
sum=(sum*10)+rev;
n=parseInt(n/10);
}
if(temp==sum)
document.getElementById("a").innerHTML="It is a palindrome";
else
document.getElementById("a").innerHTML="It is not a palindrome";
}
</script>
</body>
</html>
OUTPUT:
6.Write an HTML program including any required Javascript that receives an integer in one text field, and
check whether the number is prime or not, when the button named “Prime” is clicked
PROGRAM CODE:
<html>
<head><title>Prime</title></head>
<body>
<h3>Prime Number</h3>
<input type="button" value="Prime or not" onclick="myfun()">
<p id="a"></p>
<script>
function myfun()
{
var n=prompt("Enter n value");
var fact=1,i;
for(i=0;i<=n;i++)
{
if(n%i==0)
fact=fact+1;
}
if(fact==2)
document.getElementById("a").innerHTML="It is a prime number";
else
document.getElementById("a").innerHTML="It is not a prime number";
}
</script>
</body>
</html>
OUTPUT: