You are on page 1of 3

1.

Write JavaScript code to input a number from the user&find the sum of squares
of odd digits from 1 to the given number
CODE:
<html>
<head>
<title>abc</title>
<body>
<p>abc</p>
<script>
var i,n;
var sum=0;
n=window.prompt("Enter the number: ");
for(i=1;i<=n;i++)
{
if(i%2!=0)
{
sum=sum+(i*i);
}
}
document.writeln("The sum of square of odd digits from 1 to "+n+"is "+sum);
</script>
</head>
</body>
</html>

2.Write javascript function to find out whether the given number is even or odd
CODE:
<html>
<title>abc</title>
<body>
<p>abc</p>
<script>
var n;
n=window.prompt("Enter a number:");
if(n%2==0)
{
document.writeln(+n+" is even");
}
else{
document.writeln(+n+" is odd");
}
</script>
</body>
</html>

3. Write JavaScript program to accept lower and upper range in number. Display
sum of all even numbers between the ranges.
CODE:
<html>
<head>
<title>abc</title>
</head>
<body>
<p>abc</p>
<script language="JavaScript">
var i,a,b;
var sum=0;
a=window.prompt("Enter the lower range:");
b=window.prompt("Enter the upper range:");
for(i=a;i<=b;i++)
{
if(i%2==0)
{
sum=sum+i;
}
}
document.writeln("The sum of all even numbers between "+a+" and "+b+" is
"+sum);
</script>
</body>
</html>

4. Write JavaScript code which will change the background color of body of HTML
page on click of respective color buttons- Red, Green, Blue present on HTML form.
CODE:
<html>
<head>
<title>Gunjan Jadhav Rollno.37</title>
<script language="javascript">
var color;
function chBackcolor(color)
{
document.body.style.background=color;
}
</script>
</head>
<body>
<p>Gunjan Jadhav</p>
RED<input type="button" onclick="chBackcolor('red');">
BLUE<input type="button" onclick="chBackcolor('blue');">
GREEN<input type="button" onclick="chBackcolor('green');">
</body>
</html>

You might also like