怎么運(yùn)行不出結(jié)果?
<!DOCTYPE ?HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函數(shù)</title>
<script type="text/javascript">
//定義函數(shù)
funtion add(x,y){
? ? var x,y;
}
//函數(shù)體,判斷兩個(gè)整數(shù)比較的三種情況
if(x>y){
? ? document.write("最大值為:"+x);
}else if(x<y){
? ? document.write("最大值為:"+y);
}else{
? ? document.write(x=y);
}
?
//調(diào)用函數(shù),實(shí)現(xiàn)下面兩組數(shù)中,返回較大值。
var a=add(5,4);
var b=add(6,3);
? document.write(" 5 和 4 的較大值是:"+a+"<br>");
? document.write(" 6 和 3 的較大值是:"+b );?
</script>
</head>
<body>
</body>
</html>
2017-04-26
你的document.write(x=y)應(yīng)該換成document.write(“x=y”);
2017-04-26
<!DOCTYPE ?HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函數(shù)</title>
<script type="text/javascript">
//定義函數(shù)
function compare(x,y)
{
? ? if(x>y)
? ? {
? ? ? ? return x;
? ? }else if(x<y)
? ? {
? ? ? ? return y;
? ? }
? ? else
? ? {
? ? ? ? return "x=y";
? ? }
}
//函數(shù)體,判斷兩個(gè)整數(shù)比較的三種情況
?var ?a=compare(5,4);
?var b=compare(6,3);
?
//調(diào)用函數(shù),實(shí)現(xiàn)下面兩組數(shù)中,返回較大值。
? document.write(" 5 和 4 的較大值是:"+a+"<br>");
? document.write(" 6 和 3 的較大值是:" +b);?
</script>
</head>
<body>
</body>
</html>
也可以這么寫
2017-04-26
還有兄弟你function 寫成了funtion ,add這個(gè)函數(shù)你沒寫返回值return 不能用變量a=add(3,4)這樣賦值
2017-04-26
<!DOCTYPE ?HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函數(shù)</title>
<script type="text/javascript">
//定義函數(shù)
function add( x, y)
{
? ? ? if(x>y){
? ? document.write(x);
? ? }else if(x<y){
? ? document.write(y);
? ? }else{
? ? document.write("x=y");
? ? }
}
?
? document.write(" 5 和 4 的較大值是:");
? add( 5, 4);
? document.write(" 6 和 3 的較大值是:" );?
? add(6,3);
</script>
</head>
<body>
</body>
</html>
2017-04-26
而且 if else語(yǔ)句應(yīng)該寫在函數(shù)體add里面