為啥運行木有結果
?
<!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){ ????if(a>b){ return?a; ????} ????else?if(b>a){ return?b; ????} ????else{ ????????return?"相等" ????} ????} ??document.write("?5?和?4?的較大值是:"+add(5,4)+"<br>"); ??document.write("?6?和?3?的較大值是:"+add(6,3);? </script> </head> <body> </body> </html>
?
2015-12-04
兩個錯誤?
1、else if 后面沒寫條件
2、add(6,3)后面差個 ) ? ?
細心點,加油。
2015-12-04
<!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) {
? ? ? ? if (a > b) {
? ? ? ? ? ? return a;
? ? ? ? } else if(a<b) {
? ? ? ? ? ? return b;
? ? ? ? } else {
? ? ? ? ? ? return "相等";
? ? ? ? }
? ? }
? ? document.write(" 5 和 4 的較大值是:" + add(5, 4) + "<br>");
? ? document.write(" 6 和 3 的較大值是:" + add(6, 3));
? ? </script>
</head>
<body>
</body>
</html>