Java Script


JavaScript Tutorial


Admission Enquiry Form


Practice Example in JavaScript

Light on off in JavaScript

<html>
<head>
<title>Untitled Document</title>
<script>
var x=0;
function light()
{
if(x==0)
{
document.getElementById("offlight").src="on-light.jpg";
document.getElementById("off").src="on.jpg";
x=1;
}
else
{
document.getElementById("offlight").src="off-light.jpg";
document.getElementById("off").src="off1.png";
x=0;
}

}

</script>
</head>

<body>
<img src="off-light.jpg" id="offlight">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<img src="off1.png" id="off" onClick="light()">
</body>
</html>


Output:


Untitled Document           


Output:

The program above will display :

The sum is 30
The subtraction is 10
The multiplication is 200
The division is 2