Thankful girl
Thankful girl

Reputation: 9

I don't know how to get buttons associated correctly

Hello I am very new and I don't know all the things I need to know to do this. I need the buttons to associate with ticket sales corresponding to type and, I want it to terminate after reaching a changable number of sales. I have written the code for everything I know how to do so far so if something appears left out its probably cause I am a idiot who doesn't know what I am doing

<div align="center">
    <div>Hello, and welcome to the Porpoise Pond Virtual Ticket Booth. We are running a special so toddlers get in for free!</div>
    <div>This menu is here to simplify ticket sales. It will automatically stop when the ticket sales when the seats are sold out</div>
    <div>Be aware that the maxium amount of ticket that can be purchased in one transaction is 10!</div>
    <div>Please press the button with the type of ticket you wish to purchase  to start ordering your tickets now.</div>
      <button onclick="Calculate();">Toddler Ticket</button>
    <button onclick="Calculate();">Junior Ticket</button>
    <button onclick="Calculate();">Adult Ticket</button>
    <div id='msg'></div>

</head>

<body>
    <script type="text/javascript">
        // Program name: Ticket Booth
        // Purpose: To do a transaction
        // Author: Ephraim Vickers
        // Date last modified: Today

        // Variables
            var MAX_SEAT_COUNT = 10             //Named constant
            var amountTicket                    //Amount of tickets bought
            var grossProfit
                    //Ticket prices
            var adulTicket = 0           
            var junTicket = 0
            var todTicket = 0
            var totalSales = 0                  // adulTicket + junTicket 
                    //Seats by class
            var adulNum = 0                     // number of tickets bought
            var junNum = 0
            var todNum = 0
            var extraNum = 0                    //Ticket bought over maximum

        function parseFloat(amountTicket) {

            if (amountTicket >= MAX_SEAT_COUNT) {
                extraNum = amountTicket - MAX_SEAT_COUNT;
                document.getElementById('msg').innerHTML = "Tickets have now sold out thank you for purchasing."  // important to stop after limit
                 //end loop and display all data here like shown below remember to line up columns
                 //Ticket sale Report  <current date>
  // SEAT CAPACITY   EXTRAS            TOTAL SOLD
  // MAX_SEAT_COUNT  extraNum          amountTicket

  //  TODDLERS    JUNIORS               ADULTS
  //  todNum      junNum                  adulNum 
  //Gross Profit for today was grossProfit

              }else if    (amountTicket > 10) {
                 document.getElementById('msg').innerHTML = "The maximum number of tickets that can be done in one transaction is 10"
              }else {
                   amountTicket = prompt("Valued customer, please enter the number of tickets you would like to purchase.");
            parseFloat(amountTicket);
              }
              return;
              }
    function Calculate() {
        //set zeroes for all values
        adulTicket = 0
        junTicket = 0
        todTicket = 0
        amountTicket = 0
        totalSales = 0
        adulNum = 0
        junNum = 0
        todNUm = 0
        extraNum = 0
        grossProfit = 0
       //get user input
            amountTicket = prompt("Valued customer, please enter the number of tickets you would like to purchase.");
            parseFloat(amountTicket);
        grossProfit =  (adulTicket * adultNum) + (junTicket * junNum)

    }

    </script>

Upvotes: 0

Views: 41

Answers (1)

Marcos Gonz&#225;lez
Marcos Gonz&#225;lez

Reputation: 172

You can pass a id variable to the Calculate function like:

<button onclick="Calculate(0);">Toddler Ticket</button>
<button onclick="Calculate(1);">Junior Ticket</button>
<button onclick="Calculate(2);">Adult Ticket</button>

Then you can use this id to identify what button was pressed:

function Calculate(id) {
        //set zeroes for all values
        adulTicket = 0
        junTicket = 0
        todTicket = 0
        amountTicket = 0
        totalSales = 0
        adulNum = 0
        junNum = 0
        todNUm = 0
        extraNum = 0
        grossProfit = 0
        switch(id){
        case 0:
        //code for toddler
        break;
        case 1:
        //code  for junior
        break;
        case 2:
        // code for adult
        break;
        }
       //get user input
            amountTicket = prompt("Valued customer, please enter the number of tickets you would like to purchase.");
            parseFloat(amountTicket);
        grossProfit =  (adulTicket * adultNum) + (junTicket * junNum)

    }

I hope that works for you.

Upvotes: 1

Related Questions