javaScript function return 問題
我是JavaScript 新手,請大家多多指教~我在寫gcd時,有時會顯示值,但有時候會顯示undefined,不知道是哪裡錯了???
alert(gcd(27,8)); //undefined
function gcd(x,y){
var a,b=0;
if(x>y){
a=x; b=y;
}else{
a=y; b=x;
}
var c = a%b;
if(c!=0){
gcd(b,c);
}else{
return b;
}
} [b]回復 [url=http://jsgears.com/redirect.php?goto=findpost&pid=3818&ptid=2394]1#[/url] [i]choubaby[/i] [/b][code]
return gcd(b,c);
[/code]
頁:
[1]