-3

document.writeコードのセクションに複数の変数を表示しようとすると、コードが実行されません。私はすべてを正しく行っていたと確信しています。


<script type="text/javascript">
var name = prompt("Welcome to the Fruity Store. What is your name?","");
var product = prompt("What is the name of the product you would like?","");
var price = 1*prompt("How much does it cost?","");
var quantity = 1*prompt("How many of the fruit would you like?","");
var discount = 1*prompt("What was the discount of the product in decimal form?","");
var costoforder = (price*quantity);
var discounted = (price*quantity*discount);
var totalorder = (costoforder - discounted);

document.write("Thank you for placing an order with us " +name ) 
document.write("<p>The cost of buying " +quantity "of " +product "is " +costoforder    </p>)
document.write("<p>The discount for this purchase is " +discounted </p>)
document.write("<p>With discount, your total order cost is " +totalorder</p>)

</script>
4

3 に答える 3

1

文字列連結にいくつかのプラス記号がありません。

"<p>The cost of buying " + quantity + " of " + product + " is " + etc.
于 2013-03-13T02:34:28.133 に答える
0

変数の後に「+」記号がありません。

あなたが置く

"String" + variable "string"

それ以外の

"string" + variable + "string"

document.write ステートメントで数回

于 2013-03-13T02:36:27.797 に答える
0

+文字列連結にはプラス記号 を使用する必要があります。また、 ; がありません。ステートメントの後。

<script type="text/javascript">
var name = prompt("Welcome to the Fruity Store. What is your name?","");
var product = prompt("What is the name of the product you would like?","");
var price = 1*prompt("How much does it cost?","");
var quantity = 1*prompt("How many of the fruit would you like?","");
var discount = 1*prompt("What was the discount of the product in decimal form?","");
var costoforder = (price*quantity);
var discounted = (price*quantity*discount);
var totalorder = (costoforder - discounted);

document.write("Thank you for placing an order with us " + name ); 
document.write("<p>The cost of buying " + quantity + "of " + product + "is " + costoforder   + "</p>");
document.write("<p>The discount for this purchase is " + discounted + "</p>");
document.write("<p>With discount, your total order cost is " +totalorder + "</p>");

</script>
于 2013-03-13T02:38:35.033 に答える