2017-05-08 14 views
0

2つのアラート(同じものです) "アラート("注文したピザは "+ fullOrder"です)実際には正しく動作しません。私が警報に着くまで、すべてが正常に実行され、その後彼らは表示されません。私のアラートボックスが機能していません

私が間違っていたことを知っている人はいますか?私は何をする必要があるのか​​気にしない考えがありますが、 tはそれについて移動する方法を知っている。機能のため、他の機能の計算に行く必要fullOrder()VAR()内のローカル変数を。!!

すでに言及0​​

<html> 
 
<script> 
 

 
//Global variables 
 
var totalNumber = 0; // Total number of pizzas ordered 
 
var pizzaPrice = 9.50; // price of plain pizza 
 
var pizzaPriceGourmet = 15.50; //price of gourmet pizza 
 
var orderTotalPrice = 0; // total cost of order 
 
var pizzaDeliveryPrice = 5; // price for pizza delivery 
 
var FullOrder = 0; // number of pizza's ordered 
 
var customerName = prompt("Please enter your name.") //prompt to get the customers name 
 
var customerNumber = prompt("Please enter your phone number.") //prompt to get the customers number 
 
{ 
 
if (isNaN(customerNumber) || customerNumber < 8400000 || customerNumber > 999999999) {   // Checks if customerNumber is greater than 9999999 
 
     alert("Please enter a 7-digit telephone number between 8600000 - 9999999 Select the 'cancel order' button and enter a valid telephone number!"); \t \t \t // asks customer to enter a valid telephone number 
 
} else \t 
 
\t alert("Lets continue!"); \t \t \t // Continues to main website 
 
} 
 

 

 
order();//call order 
 

 
calculate(totalGourmet,totalPlain);// while calling 
 
    
 
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 
 

 
    totalPlain = pizza[0] + pizza[1] + pizza[2] + pizza[3] + pizza[4]; 
 
    totalGourmet = pizza[5] + pizza[6] + pizza[7]; 
 

 
    var totalNumber = totalGourmet + totalPlain 
 

 
    var fullOrder = alert("You have ordered: " + "\n" +  <----- I NEED THIS 
 
     "Hawaiian Pizza ($9.50): " + pizza [0] + "\n" + 
 
     "Cheese Pizza ($9.50): " + pizza [1] + "\n" + 
 
     "Veggie Pizza ($9.50): " + pizza [2] + "\n" + 
 
     "Supreme Pizza ($9.50): " + pizza [3] + "\n" + 
 
     "Pepperoni Pizza ($9.50): " + pizza [4] + "\n" + 
 
     "Meat-Lovers Pizza ($15.50): " + pizza [5] + "\n" + 
 
     "Chicken Pizza ($15.50): " + pizza [6] + "\n" + 
 
     "Prawn Pizza ($15.50): " + pizza [7]); 
 
\t \t 
 

 
    if (totalNumber >12) {   // Limit for total amount of Pizzas ordered 
 
     alert("There is a limit of 12 pizzas per order. - PRESS 'Prevent this page from creating  additional dialogs' THEN PRESS 'cancel order' AND THEN RE-ORDER! - Current total is: " +totalNumber); 
 
    } else 
 
     alert("Total number of pizzas ordered: " + totalNumber); //Total amount of pizzas ordered 
 
    calculate(totalGourmet,totalPlain) //Begins calculation function 
 
} 
 

 

 
function calculate(totalGourmet,totalPlain) //Function for the cost of the order 
 
{ 
 
    orderTotalPrice = (totalPlain*pizzaPrice + totalGourmet*pizzaPriceGourmet); //order total+ amount of pizzas ordered * pizza price 
 
    var pizzaDelivery = prompt('Would you like your order to be delivered for $5, or for pick up? -Type in "1" for delivery, and "0" for pickup.') //asks if you want your order to be delivered or pickup 
 
    orderTotalPrice = (orderTotalPrice + (pizzaDelivery*pizzaDeliveryPrice)); // calculates the total cost with/without the delivery cost 
 
    alert("Total cost of pizzas is: $" + orderTotalPrice.toFixed(2)); //Display order cost as "$"0.00 (2 decimal points) 
 
    if (pizzaDelivery == '1'){ 
 
     var response = prompt("Please enter your address: ") 
 
     alert("Your pizza should be delivered within the next 25 minutes, to this address: " +response) 
 
     alert("Thank you for ordering with Pete's Pizzas " +customerName) 
 
     alert("If anything goes wrong we will contact you on your number: " +customerNumber) 
 
\t \t alert("The pizzas you ordered are: " +fullOrder) \t <----TO BE HERE 
 
     alert("Your order details are: " +customerName +"\n" +customerNumber +"\n" +response) 
 
     alert("To exit, just click 'ok' and then close down the program!") 
 
    } else if (pizzaDelivery == '0'){ 
 
     alert("Your order will be ready for pickup in 15 minutes!") 
 
     alert("Thank you for ordering with Pete's Pizzas " +customerName) 
 
     alert("If anything goes wrong we will contact you on your number: " +customerNumber) 
 
\t \t alert("The pizzas you ordered are: " +fullOrder) \t <----TO BE HERE 
 
     alert("Your order details are: " +customerName +"\n" +customerNumber) 
 
     alert("To exit, just click 'ok' and then close down the program!") 
 
    } 
 
} 
 

 
</script> 
 

 
<body> 
 
<h1> Welcome to Pete's Pizza! </h1> 
 
<p> Please follow the prompts to place your order. </p> 
 
<h2> Menu: </h2> 
 
<h3>($9.50) Hawaiian, Cheese, Veggie, supreme, pepperoni.</h3> 
 
<h3>($15.50) meat-lovers, chicken, prawn. </h3> 
 
<p><b>BE AWARE</b> that there is a $5 charge for deliveries. </p> 
 
<p> (Please note : Maximum 12 pizzas per Order) </p> 
 

 
<form name ="form">        
 
     
 
<input type="text" name= "hawaiian" > Hawaiian Pizza <br> 
 
<input type="text" name= "cheese" > Cheese Pizza <br> 
 
<input type="text" name= "veggie" > Veggie Pizza <br> 
 
<input type="text" name= "supreme" > Supreme Pizza <br> 
 
<input type="text" name= "pepperoni" > Pepperoni Pizza <br> 
 
<input type="text" name= "meatlovers" > MeatLovers Pizza <br> 
 
<input type="text" name= "chicken" > Chicken Pizza <br> 
 
<input type="text" name= "prawn" > Prawn Pizza <br> 
 

 
<input type="button" value="order now" onClick="order()"> 
 
<input type="button" value="cancel order" onClick="window.location.reload()"> 
 
</form> 
 

 

 

 
<i> If you need to cancel the order press the 'Prevent this page from creating  additional dialogs' button, then press the "cancel order" button. (This will take you back to the begging of the program.) </i> 
 
</body> 
 
    
 
</html>

+5

まず、 – Weedoze

+0

は、あなたのブラウザのコンソールで見て、構文エラーを修正し、あなたはおそらく、余分な開口部ブラケットは、私が使うのですか、構文エラーを修正した後 – Pete

+0

あるJSエラーを持っています関数のorder()からの変数fullOrderを関数calculate()に入れ、依然として注文の詳細を保持しますか? – KPWH

答えて

0

を助けてください@Weedoze、あなたのコードにいくつかの構文エラーがあります。それらを解決するだけで問題が解決しました。実行中のコードを確認することができますhere。より正確には、このラインのいくつかの用途があります。

<----- I NEED THIS 

将来的には、構文エラーを防ぐために構築するには、構文の強調表示などの適切なIDEまたは単にテキストエディタを使用することができます。

+0

ああ、私は<---コメントありがとう! – KPWH

0

javascriptとhtmlのコメントは異なります。

<html> 
 
<script> 
 

 
//Global variables 
 
var totalNumber = 0; // Total number of pizzas ordered 
 
var pizzaPrice = 9.50; // price of plain pizza 
 
var pizzaPriceGourmet = 15.50; //price of gourmet pizza 
 
var orderTotalPrice = 0; // total cost of order 
 
var pizzaDeliveryPrice = 5; // price for pizza delivery 
 
var FullOrder = 0; // number of pizza's ordered 
 
var customerName = prompt("Please enter your name.") //prompt to get the customers name 
 
var customerNumber = prompt("Please enter your phone number.") //prompt to get the customers number 
 
{ 
 
if (isNaN(customerNumber) || customerNumber < 8400000 || customerNumber > 999999999) {   // Checks if customerNumber is greater than 9999999 
 
     alert("Please enter a 7-digit telephone number between 8600000 - 9999999 Select the 'cancel order' button and enter a valid telephone number!");  // asks customer to enter a valid telephone number 
 
} else 
 
    alert("Lets continue!");  // Continues to main website 
 
} 
 

 

 
order();//call order 
 

 
calculate(totalGourmet,totalPlain);// while calling 
 
    
 
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 
 

 
    totalPlain = pizza[0] + pizza[1] + pizza[2] + pizza[3] + pizza[4]; 
 
    totalGourmet = pizza[5] + pizza[6] + pizza[7]; 
 

 
    var totalNumber = totalGourmet + totalPlain 
 

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

 
    if (totalNumber >12) {   // Limit for total amount of Pizzas ordered 
 
     alert("There is a limit of 12 pizzas per order. - PRESS 'Prevent this page from creating  additional dialogs' THEN PRESS 'cancel order' AND THEN RE-ORDER! - Current total is: " +totalNumber); 
 
    } else 
 
     alert("Total number of pizzas ordered: " + totalNumber); //Total amount of pizzas ordered 
 
    calculate(totalGourmet,totalPlain) //Begins calculation function 
 
} 
 

 

 
function calculate(totalGourmet,totalPlain) //Function for the cost of the order 
 
{ 
 
    orderTotalPrice = (totalPlain*pizzaPrice + totalGourmet*pizzaPriceGourmet); //order total+ amount of pizzas ordered * pizza price 
 
    var pizzaDelivery = prompt('Would you like your order to be delivered for $5, or for pick up? -Type in "1" for delivery, and "0" for pickup.') //asks if you want your order to be delivered or pickup 
 
    orderTotalPrice = (orderTotalPrice + (pizzaDelivery*pizzaDeliveryPrice)); // calculates the total cost with/without the delivery cost 
 
    alert("Total cost of pizzas is: $" + orderTotalPrice.toFixed(2)); //Display order cost as "$"0.00 (2 decimal points) 
 
    if (pizzaDelivery == '1'){ 
 
     var response = prompt("Please enter your address: ") 
 
     alert("Your pizza should be delivered within the next 25 minutes, to this address: " +response) 
 
     alert("Thank you for ordering with Pete's Pizzas " +customerName) 
 
     alert("If anything goes wrong we will contact you on your number: " +customerNumber) 
 
    alert("The pizzas you ordered are: " +fullOrder) 
 
     alert("Your order details are: " +customerName +"\n" +customerNumber +"\n" +response) 
 
     alert("To exit, just click 'ok' and then close down the program!") 
 
    } else if (pizzaDelivery == '0'){ 
 
     alert("Your order will be ready for pickup in 15 minutes!") 
 
     alert("Thank you for ordering with Pete's Pizzas " +customerName) 
 
     alert("If anything goes wrong we will contact you on your number: " +customerNumber) 
 
    alert("The pizzas you ordered are: " +fullOrder); 
 
     alert("Your order details are: " +customerName +"\n" +customerNumber) 
 
     alert("To exit, just click 'ok' and then close down the program!") 
 
    } 
 
} 
 

 
</script> 
 

 
<body> 
 
<h1> Welcome to Pete's Pizza! </h1> 
 
<p> Please follow the prompts to place your order. </p> 
 
<h2> Menu: </h2> 
 
<h3>($9.50) Hawaiian, Cheese, Veggie, supreme, pepperoni.</h3> 
 
<h3>($15.50) meat-lovers, chicken, prawn. </h3> 
 
<p><b>BE AWARE</b> that there is a $5 charge for deliveries. </p> 
 
<p> (Please note : Maximum 12 pizzas per Order) </p> 
 

 
<form name ="form">        
 
     
 
<input type="text" name= "hawaiian" > Hawaiian Pizza <br> 
 
<input type="text" name= "cheese" > Cheese Pizza <br> 
 
<input type="text" name= "veggie" > Veggie Pizza <br> 
 
<input type="text" name= "supreme" > Supreme Pizza <br> 
 
<input type="text" name= "pepperoni" > Pepperoni Pizza <br> 
 
<input type="text" name= "meatlovers" > MeatLovers Pizza <br> 
 
<input type="text" name= "chicken" > Chicken Pizza <br> 
 
<input type="text" name= "prawn" > Prawn Pizza <br> 
 

 
<input type="button" value="order now" onClick="order()"> 
 
<input type="button" value="cancel order" onClick="window.location.reload()"> 
 
</form> 
 

 

 

 
<i> If you need to cancel the order press the 'Prevent this page from creating  additional dialogs' button, then press the "cancel order" button. (This will take you back to the begging of the program.) </i> 
 
</body> 
 
    
 
</html>

関連する問題