2017-10-30 12 views
0

私のクラスに対して行う必要がある課題に対して、このコードにプロンプ​​トが表示されないようです。あなたが最後に持っている特典ポイントの量を表示するはずですが、追加のプロンプトとアラートをJSに追加すると、どのプロンプトも表示されません。何かアドバイス?私のプロンプトが動作していないようです

var numCoffees, awardPoints; 

    numCoffees = prompt("How many coffees have you purchased?"); 
    if (numCoffees == 0) 
     {awardPoints = 0;} 

    if (numCoffees == 1) 
     {awardPoints = 2;} 

    if (numCoffees == 2) 
     {awardPoints = 5;} 

    if (numCoffees == 3) 
     {awardPoints = 9;} 

    if (numCoffees > 3) 
     {awardPoints = ((9+2)*(numCoffees-3));} 

    /*Determine Preferred Customer status*/ 

var PreferredCustomer; 

    PreferredCustomer = prompt("Please say "yes" or "no" to indicate if you are a preferred customer."); 
    if (PreferredCustomer == "yes") 
     {awardPoints = awardPoints*2;} 

    /*Display award points*/ 

    alert("awardPoints" + award points); 

答えて

2

引用符に問題があります。単一引用符に最初と最後の引用符を変更します。

PreferredCustomer = prompt('Please say "yes" or "no" to indicate if you are a preferred customer.'); 

また、あなたは、内側の引用符脱出することができます

PreferredCustomer = prompt("Please say \"yes\" or \"no\" to indicate if you are a preferred customer."); 

をそして、kakamg0さんのコメントのおかげで、最後の行修正:

alert("awardPoints" + awardPoints); 
+1

、最後に 'alert'は('警戒しなければなりません"awardPoints" + awardPoints); ' – kakamg0

+0

htmlファイルを開いても最初のプロンプトが表示されません。 if文に問題があるのだろうか? –

+0

@ kakamg0うん、私のプロンプトが現れたのを修正した後。ありがとう! –

0

主にここでいくつかの構文の問題があるように見えます。論理的にコードが書かれています。引用は、二重引用符で形成された文字列内の二重引用符は、最初の二重引用符で文字列ステートメントを終了します持っ

  • 間違っている:他の指摘したように、それが書かれている方法は、

    ビット故障しています対になった

  • 警告ボックスの受賞ポイントは有効な変数ではありません。これは、スペースが含まれており、それがコードビットのアップ全体整頓

が定義されていない、あなたがで終わるだろう。また

var numCoffees, awardPoints; 

numCoffees = prompt("How many coffees have you purchased?"); 
if (numCoffees == 0) { awardPoints = 0; } else 
if (numCoffees == 1) { awardPoints = 2; } else 
if (numCoffees == 2) { awardPoints = 5; } else 
if (numCoffees == 3) { awardPoints = 9; } else 
if (numCoffees > 3) { awardPoints = ((9 + 2) * (numCoffees - 3));} 

/*Determine Preferred Customer status*/ 

var PreferredCustomer; 

PreferredCustomer = prompt("Please say 'yes'or 'no' to indicate if you are a preferred customer."); 
if (PreferredCustomer == "yes") { 
    awardPoints = awardPoints * 2; 
} 

/*Display award points*/ 

alert("awardPoints" + awardPoints); 
+0

Racil Hilanが私より少し速かったように見えますが、彼は同じ欠陥を指摘して答えに値する –

関連する問題