2017-01-16 22 views
-1
<!DOCTYPE html> 
<html> 
<head> 
<style> 

</style> 
<script> 
function convert(x){ 
return(5/9)*(x-32); 
var x = document.forms["myForm"]["box"].value; 
if (x == "") { 
    alert("Name must be filled out"); 
    return false; 
    } 
document.getElementById("answer").innerHTML =x; 

</script> 
</head> 
<body> 
<form id="myForm"> 
Farenheit:<br> 
<input type="text" id="box"/><br> 
<input type="button" value="Submit" onclick="convert()"/> 
</form> 
<p id="answer"> </p> 
</body> 
</html> 

「予期しない入力の後に= x; 私はjavascriptを使い慣れていないので、簡単な間違いかもしれません。これのポイントは、farenheitをcelciusに変換することです。 リターン(5/9)*(x-32);それを変換する方程式です。なぜ「入力の予期しない終了」と言われますか?

+4

あなたはあなたの閉鎖を逃しているがあります'' 'あなたの'関数 'のために – Wondercricket

+0

構文エラーを修正すると、コードのどの部分も実際に' answer'を更新しないことがわかります - 今すぐ "答え"が設定されているので、ページはロードされますが、もう一度ロードされません –

+0

ありがとう!しかし、コードはまだ変換された数値を表示して表示しませんか?なぜなのかご存知ですか? –

答えて

1

あなたは最後のparanthesisがありません。

<script> 
function convert(x){ 
return(5/9)*(x-32); 
var x = document.forms["myForm"]["box"].value; 
if (x == "") { 
    alert("Name must be filled out"); 
    return false; 
    } 
document.getElementById("answer").innerHTML =x; 
} 
</script> 

修正する必要があります。

0

私はあなたが探していたと信じて:

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<title>Fahrenheit to Celsius converter</title> 
 
<script> 
 
function convert(x) 
 
{ 
 
var x = document.forms.myForm.box.value; 
 
if (x === "") // keep in mind the case of 0 
 
{ 
 
    alert("Farenheit box must be filled out"); 
 
    return false; 
 
} 
 
document.getElementById("answer").innerHTML = "Celsius " + (5/9)*(x-32); 
 
} 
 
</script> 
 
</head> 
 
<body> 
 
<form name="myForm"> 
 
Farenheit:<br> 
 
<input type="text" name="box"><br> 
 
<input type="button" value="Submit" onclick="convert()"> 
 
</form> 
 
<p id="answer"></p> 
 
</body> 
 
</html>

+0

ありがとう!問題を修正する! :) –

0

2つの開口の中括弧 "{"、そして唯一のクロージング "}"

関連する問題