当我的按钮被点击时,我试图在 JavaScript 中显示价格,但它只是向我显示我的警报。谁能告诉我哪里出错了?这是我的功能:
function prompttotalCost() {
var totalCost;
var costPerCD;
var numCDs;
numCDS = prompt("Enter the number of Melanie's CDs you want to buy");
if (numCDS > 0) {
totalCost = totalCost + (costPerCD * numCDs);
alert("totalCost+(costPerCD*numCDs)");
totalCost = 0;
costPerCD = 5;
numCDs = 0;
} else {
alert("0 is NOT a valid purchase quantity. Please press 'OK' and try again");
} // end if
} // end function prompttotalCost