Computer Science, asked by aryankamble527, 6 hours ago

Write an event driven JavaScript program to display odd numbers between 1to 100.​

Answers

Answered by anindyaadhikari13
7

\textsf{\large{\underline{Solution}:}}

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>

\textsf{\large{\underline{Explanation}:}}

  • 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