你好,我是新手,我不知道我需要知道的所有事情。我需要按钮与类型对应的门票销售相关联,并且我希望它在达到可更改的销售数量后终止。到目前为止,我已经为我所知道的所有事情编写了代码,所以如果遗漏了某些内容,可能是因为我是一个不知道我在做什么的白痴
<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>
您可以将 id 变量传递给 Compute 函数,如下所示:
<button onclick="Calculate(0);">Toddler Ticket</button>
<button onclick="Calculate(1);">Junior Ticket</button>
<button onclick="Calculate(2);">Adult Ticket</button>
然后,您可以使用此 id 来识别按下的按钮:
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)
}
我希望这对你有用。