2017-01-17 8 views
-1

Javaスクリプトクラスの練習をしています。私はif文に問題があります。摂氏を計算するために作成したボタンは動作しませんが、if文を削除するとコードが実行されます。JavaScriptの新機能if文のトラブル

 <html> 
     <head> 
     <title>Template</title> 
     </head> 
     <body> 
     <h3>Lab 2</h3>`enter code here` 
     <p><input type="button" id="myButton1" value="Click here to enter   
     temperature." onclick="getTemp()" /></p> 
     <script type="text/javascript"> 

     function getTemp() 
     { 
      var enterTemp = parseInt(prompt("Enter temperature"," ")); 
      var tempType = prompt("Was that temperature in Celsius -'C' or fahrenheit - 'F'?"," "); 

       if(tempType == "C") 
       { 
       var finalTemp = enterTemp * 1.8 + 32; 
        document.write("<p> in Celsius"+finalTemp"</p>"); 
       } 

       else 
       { 
        var finalTemp = enterTemp/1.8 - 32; 
        document.write("<p> in Fahrenheit"+finalTemp"</p>"); 
       } 






      } 
     </script> 
     </body> 
     </html> 
+2

Java!= JavaScript –

+0

ようこそ!スタックオーバーフロー!宿題の助けを求めているようです。それ自体に問題はありませんが、これらのことを守ってください(http://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions/338845#338845)、それに応じて質問を編集してください。 –

答えて

0

文字列が正しく連結されていません。

はあなたが文)(両方とも書き込みにおける第二のプラス記号が欠落している

document.write("<p> in Fahrenheit" + finalTemp" + </p>"); 

であるべき。