Write an event driven JavaScript program to display odd numbers between 1to 100.
Answers
Answered by
7
The given problem is solved using language - JavaScript.
<!DOCTYPE html>
<html>
<head>
<title>
JavaScript...
</title>
<script>
function display(){
for(var i=1;i<=100;i+=2){
document.getElementById("display").innerHTML+=i+" ";
}
}
</script>
</head>
<body>
Click on the button to display odd numbers (1-100): <button onclick="display()">Go!</button><br/>
<span id="display"></span>
</body>
</html>
- The problem is solved using onclick event. When the user clicks on the button, the function display() is called which displays all the odd numbers in the range 1 to 100.
See the attachment for output.
Attachments:
Similar questions
Math,
3 hours ago
Sociology,
3 hours ago
Math,
6 hours ago
Computer Science,
7 months ago
English,
7 months ago