為什么我這個什么都不顯示,實在是找不到哪里錯了?
<!DOCTYPE? HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函數</title>
<script type="text/javascript">
//定義函數
function add(a,b){
? ? //a=prompt("請輸入第一個數");
? ? //b=prompt("請輸入第二個數");
? ??
? ? if(a>b)? ? ?{
? ? ? ? return a;
? ? ? ? ? ? ? ? ?}
? ? else if(a<b){
? ? ? ? return b;
? ? ? ? ? ? ? ? ?}
? ? ?else(a==b) {
? ? return="相等";
? ? ? ? ? ? ? ? }
}
//函數體,判斷兩個整數比較的三種情況
? ??
? ??
//調用函數,實現下面兩組數中,返回較大值。
? document.write(" 5 和 4 的較大值是:"+add(5,4)+"<br>");
? document.write(" 6 和 3 的較大值是:"+add(6,3)+"<br>");?
? ? document.write("6和6的值"+add(6,6));
</script>
</head>
<body>
? ?<!--<input type="button" value="判斷大小" onClick="add(a,b)">-->
</body>
</html>
2019-07-24
else后面不能加條件,而且return后面也不用加等號。把后面的改成? else return "相等"? 就行了。(也只有a=b的情況了嘛)
2019-08-07
有兩個地方錯誤,1,return不用加等號,else不用加條件,都是語法錯誤