我正在嘗試在一個函數內部創建一個while循環,該函數將打印出「我在循環!」這個短語。 3次。我有困難,字符串打印未定義。它雖然打印三次。我怎樣才能讓字符串打印我想要的短語?打印的字符串顯示爲undefined
我收到此錯誤Oops, try again. It looks like you're not printing the right string to the console.
var count = 0;
var loop = "I'm looping!";
var loop = function(){
while(count < 3){
console.log(loop(count++));
}
};
loop();
我試圖把我的循環變量的函數內部。我也曾嘗試把短語"I'm looping!"
內環路()的,就像這樣:
loop("I'm looping!");
我在做什麼錯?
謝謝!爲什麼我無法做到這一點呢? 'console.log(loop_str(count ++));' – Paul
@Paul:你期望'loop_str(count ++)'做什麼? 'loop_str'是一個*字符串*,不是函數。你爲什麼要把'count'傳遞給'loop_str'? –
那麼,這是否正在聲明一個函數? 'loop_str(count ++)' – Paul