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

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!