JavaScript Practice Questions And Answer

Problem: Write a program for generating electricity Bill. Accept last month unit and current month unit from user, then calculate and print bill amount according to following condition:
0-150 charges 4 rs/unit
151-300 charges 6 rs/unit
301-500 charges 8rs/unit
>500 charges 10rs/unit
Solution:
<html>
 <head>
  <script>
   function electBill()
  {
    var last = 6700
    var current = 6830
    var totalUnit = current-last 
    if(totalUnit>0 && totalUnit<=150)
    {
      var charges = totalUnit*4
      document.write("Bill amount:" + charges )
    }
     else if(totalUnit>=151 && totalUnit<=300)
    {
      var charges = totalUnit*6
      document.write("Bill amount:" + charges )
    }
     else if(totalUnit>300 && totalUnit<=500)
    {
      var charges = totalUnit*8
      document.write("Bill amount:" + charges )
    }
     else
    {
      var charges = totalUnit*10
      document.write("Bill amount:" + charges )
    }
   }
  </script>
 </head>
    <body>
        <input type="button" value="Go" onclick="electBill()"/>
    </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!