JavaScript Practice Questions And Answer

Problem: Find sum of first , third and fifth digit of 6 digit number.
Solution:
            <html>
             <head>
              <script>
               function digitSum()
               {
                var inputBox = document.getElementById("input1")
                var n = parseInt(inputBox.value)
                var n1 = parseInt(n/10) 
                var d1 = n%10 

                var n2 = parseInt(n1/10)
                var d2 = n1 % 10

                var n3 = parseInt(n2/10)
                var d3 = n2%10

                var n4 = parseInt(n3/10)
                var d4 = n3%10

                var n5 = parseInt(n4/10)
                var d5 = n4 % 10
                var d6 = n5

                var sum  = d6 + d4 + d2
                //document.write(sum)
                alert(sum)
                inputBox.value=""
               }
              </script>
             </head>
             <body>
              <input type="text" placeholder="Enter a number" id="input1"/>
              <br>
              <input type="button" value="sum digit" id="button1" onclick="digitSum()"/>
             </body>
           </html>
          

Contact Us

Our Address

Office no.- 401,Shekhar Central Building ,Palasiya, Pin-code:452001, Indore

Email Us

contact@codebetter.in

Call Us

+91 88230 75444, +91 99939 28766

Loading
Your message has been sent. Thank you!