我如何设置它,以便有两种不同的价格

How do I set it up so there is two different prices

本文关键字:两种 何设置 设置      更新时间:2023-09-26

如何让我的程序工作,以便它有美食比萨饼和普通比萨饼的单独价格?然后将它们与计算函数相加。

因此,如果我订购 1 个普通披萨和 1 个美食,它会给我适当的成本。

常规披萨是:夏威夷,奶酪,素食,至尊,意大利辣香肠,美味的披萨是:肉类爱好者,鸡肉,虾。

<html>
<title> Pete's Pizza </title>
<script>

//Menu: Hawaiian, Cheese, Veggie, supreme, pepperoni, meat-lovers, chicken, prawn.
//global variables
var totalNumber = 0;   // for total number of Pizzas ordered
var pizzaPrice = 9.50;   // price of each pizza
var pizzaPriceGourmet = 15.50;  //price for gourmet pizzas
var pizzaDelivery = 5;  //price for pizza delivery
var orderTotalPrice = 0;   // total cost of order

function order()
{
  var pizza = new Array()
  pizza[0] = document.form.hawaiian.value                //allocates type of pizza in array
  pizza[0] = Number(pizza[0])                            //converts to number value
  pizza[1] = document.form.cheese.value                 //allocates type of pizza in array            
  pizza[1] = Number(pizza[1])                            //converts to number value
  pizza[2] = document.form.veggie.value                //allocates type of pizza in array
  pizza[2] = Number(pizza[2])                            //converts to number value
  pizza[3] = document.form.supreme.value                //allocates type of pizza in array
  pizza[3] = Number(pizza[3])                            //converts to number value
  pizza[4] = document.form.pepperoni.value                //allocates type of pizza in array
  pizza[4] = Number(pizza[4])                            //converts to number value
  pizza[5] = document.form.meatlovers.value                //allocates type of pizza in array
  pizza[5] = Number(pizza[5])                            //converts to number value
  pizza[6] = document.form.chicken.value                //allocates type of pizza in array
  pizza[6] = Number(pizza[6])                            //converts to number value
  pizza[7] = document.form.prawn.value                //allocates type of pizza in array
  pizza[7] = Number(pizza[7])                            //converts to number value
  totalNumber = pizza[0] + pizza[1] + pizza[2] + pizza[3] + pizza[4] + pizza[5] + pizza[6] + pizza [7];

 alert("You have ordered:" + "'n" +        
         "Hawaiian Pizza:" + pizza [0] + "'n" +
         "Cheese Pizza:" + pizza [1] + "'n" +
         "Veggie Pizza:" + pizza [2] + "'n" + 
         "Supreme Pizza:" + pizza [3] + "'n" +
         "Pepperoni Pizza:" + pizza [4] + "'n" +
         "Meat-Lovers Pizza:" + pizza [5] + "'n" +
         "Chicken Pizza:" + pizza [6] + "'n" +
         "Prawn Pizza:" + pizza [7]);   

if (totalNumber >12) {          // Limit for total amount of Pizzas ordered
    alert("There is a limit of 12 pizzas per order. Please cancel Order and re-order. Current total is:" +totalNumber);
    } else 
    alert("Total number of burgers ordered:" + totalNumber); //Total amount of pizzas ordered
    calculate()  //Begins calculation function
}

function calculate()    //Function for the cost of the order
{
    orderTotalPrice = (totalNumber*pizzaPrice + totalNumber*pizzaPriceGourmet);  //order total+ amount of pizzas ordered * pizza price
    alert("Total cost of pizzas is: $" + orderTotalPrice.toFixed(2) );  //Display order cost as "$"0.00
}
</script>

你需要美味的披萨价格吗?

单独为所有比萨饼设置价格。 然后从订购的 X 价格中获取总数。

然后在最后添加总计以获得价格

声明函数

外部的变量以在任何地方使用,即使这意味着声明一个空函数

var披萨1;