求大神解答這樣有問題么??。?!
<!DOCTYPE ?HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函數</title>
<script type="text/javascript">
function compare(a,b)
? ? { ?
? ? ? ? if(a>=b){
? ? ? ? {if(a>b)
? ? ? ? ? ?return a;
? ? ? ? else{return "兩數相等";}}
? ? ? ? else{return b;}
? ? } ? ?
? document.write(" 5 和 4 的較大值是:"+compare(5,4)+"<br/>");
? document.write(" 6 和 3 的較大值是:"+compare(6,3)+"<br/>");?
? document.write(" 88 和88 的較大值是:"+compare(88,88) );?
</script>
</head>
<body>
</body>
</html>
2016-12-14
函數是返回兩個數的最大值,返回的是數值,相等的時候返回任何一個就可以了,不要返回字符串“兩數相等”。 function?max(a,?b)?{ ????if(a>b)?{ ????????return?a; ????}?else?{ ????????return?b; ????} } 或者使用條件表達式更簡單 function?max(a,?b)?{ ????return?a?>?b???a?:?b; }