JavaScript Practice Questions And Answer

Problem: Write a program to print all even or odd numbers in given range using recursion.
Solution:
<html>
 <head>
  <title>Recursion</title>
   <script>
    function even(a,b)
    {
      if(a%2==0)
      {
       document.write("<br>", a)
      }
       if(a>=b)
       {
         return
       }
        a = a + 1;
        even(a,b)
      }
       function demo1()
       {
         var n1 = parseInt(document.getElementById("input1").value);
         var n2 = parseInt(document.getElementById("input2").value);
         document.write("Even numbers are:")
         even(n1,n2)
        }
  </script>
</head>
 <body>
      <input type="text" id="input1" placeholder="Enter Number"><br><br>
      <input type="text" id="input2" placeholder="Enter Number"><br><br>
      <input type="button" id="btn" value="GO" onclick="demo1()">
      <div id="result"></div>
 </body>
 </html>      

Contact Us

Our Address

Plot No. 64, PU-4, Scheme 54, Behind C21 Mall near Hotel Holiday , AB Road, Indore Pin-code:452001

Email Us

contact@codebetter.in

Call Us

+91 88230 75444, +91 99939 28766

Loading
Your message has been sent. Thank you!