HTML Programs to Study for Unit Tests
HTML Programs to Study for Unit Tests
JAVASCRIPT PROGRAMS
<!DOCTYPE html>
<html>
<head><title> odd /even </title></head>
<body>
<script language ="javascript">
var a,b;
a =prompt("Enter your value : ");
b=parseInt(a);
if(b%2==0)
alert("number is even");
else
alert("number is odd");
</script></body></html>
<html>
<head> <title> Multiplication </title></head>
<body bgcolor="yellow">
<script language="javascript">
var a,b; // defining the variables
a=prompt("enter a value : ");
b = a*a;
document.write("<br> square of "+a+" is " +b);
</script>
</body></html>
The same program using a function
<html>
<head> <title> Square function </title>
<script language="javascript">
function square(m)
{var x= m*m;
return(x);
}
</script>
</head>
<body bgcolor="yellow">
<h1> Program to square a number</h1>
<script language="javascript">
var a,b; // defining the variables
a=prompt("enter the number : ");
c=square(a);
document.write("<br> <h2> square of " +a+" = "+c+"</h2>");
</script></body></html>
3) Create two buttons and have event handlers such that the mouse moves over one
button the background colour changes and if someone clicks on the other button the
background colour changes.
<html>
<head> <title> To change colour using MouseOver</title></head>
<body>
<script language ="JavaScript">
function changeBG(color)
{document.bgColor=color;
}
</script>
<form>
<input type= "button" value="Move mouse over me" name="Yellow"
onMouseOver ="changeBG('Yellow')"
onMouseOut="changeBG('blue')"><br>
<input type= "button" value="click me" name="Green" onClick ="changeBG('Green')">
</form></body></html>