-2
我正在嘗試計算總費用,並使用警報顯示用戶點擊「提交」按鈕時的總費用。我不知道如何從其他函數調用var。有沒有辦法做到這一點?任何幫助將不勝感激。謝謝!如何在JavaScript中調用其他函數的變量?
<script type = "text/javascript">
function CostCalculate(){
var TotalCost = AppleCost + OrangeCost + BananaCost;
alert("Your total cost is $ " + TotalCost);
}
function getQuantity1(){
var promptNum = prompt("Enter numbers of Apple: ");
var AppleNum = parseInt(promptNum);
var AppleCost = AppleNum * 0.59;
}
function getQuantity2(){
var promptNum = prompt("Enter numbers of Orange: ");
var OrangeNum = parseInt(promptNum);
var OrangeCost = OrangeNum * 0.49;
}
function getQuantity3(){
var promptNum = prompt("Enter numbers of Banana: ");
var BananaNum = parseInt(promptNum);
var BananaCost = BananaNum * 0.39;
}