JavaScript Practice Questions And Answer

Problem: Write a code for call center (using nested switch case). E,g, 1 for prepaid, 2 for post paid. If 1 selected then show all the options for prepaid.
Solution:
<html>
 <head>
  <script>
   function demo1()
  {
    var str = prompt("Enter your choice: 1. prepaid, 2.Postpaid")
    var choice = parseInt(str)
     switch(choice)
    {
     case 1: 
             msg = ("Prepaid plans \n")
             msg = msg + ("1. 10Rs talktime 40Rs \n")
             msg = msg +("2. 20Rs talktime 100Rs \n")
             msg = msg +("3. 50Rs talktime 200Rs \n")
             msg = msg +("4. 200Rs talktime unlimited \n")
             var str2 = prompt("Enter your choice:out of 1 to 4" + msg)
             var choice2 = parseInt(str2)
             document.write("You selected plan no."+choice2)
             break
     case 2: 
             msg2 = ("Postpaid plans \n")
             msg2 = msg2 + ("1. 100Rs talktime 1month \n")
             msg2 = msg2 +("2. 200Rs talktime 3month \n")
             msg2 = msg2 +("3. 500Rs talktime year \n")
             msg2 = msg2 +("4. 600 talktime 1.5year \n")
             var str3 = prompt("Enter your choice:out of 1 to 4" + msg2)
             var choice3 = parseInt(str3)
             document.write("You selected plan no."+choice3)
        }
      }
  </script>
 </head>
  <body>
      <input type="button" value="Go" onclick="demo1()" />
  </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!