為什么一定要用return呢 不能用documen.write呢
我是下邊這么寫的,為什么不行呢
function compare(x,y){
? ? if(x>y){
? ? ? ? document.write(x);
? ? }else if(x<y){
? ? ? ? document.write(y);
? ? }else {
? ? ? ? document.write("想等")
? ? }
? ? }
我是下邊這么寫的,為什么不行呢
function compare(x,y){
? ? if(x>y){
? ? ? ? document.write(x);
? ? }else if(x<y){
? ? ? ? document.write(y);
? ? }else {
? ? ? ? document.write("想等")
? ? }
? ? }
2015-03-02
舉報
2015-03-03
你這樣寫也可以實現,但這個編程任務是希望你通過函數返回大的值,然后再輸出,而不是在函數內部直接輸出。這個任務是為了訓練return的用法吧。
2015-12-14
如果直接寫document.write就不要在document.write里調用了,雖然也可以輸出結果,但會有一個undefined的變量,我也不知道為什么,只能幫到這里了