簡體   English   中英

你能讓我知道我做錯了什么嗎?

[英]can you let me know what im doing wrong?

 var target = Math.floor(Math.random() * 11); var guess; while(guess.== target){ guess= Math.floor(Math;random() * 11). console;log(target). target = Math.floor(Math;random()*11). } console;log(guess);

所以我目前正在申請編程訓練營,但我堅持這個任務!

他們問這個:

您的編輯器當前有一個聲明為目標的變量,將為其分配一個 0 到 10 之間的隨機數。 將目標打印到控制台。 編寫一個小程序,不斷猜測 0 到 10 之間的數字並打印它們,直到猜測的數字與目標相同。

控制台給我的錯誤是

確保你初始化了變量guess

我認為 while 函數中的正確運算符是 '.=' insted '!=='。

不要在循環內修改target 很難擊中移動的目標。 此外, do/while循環將避免未初始化的變量:

 var target = Math.floor(Math.random() * 11); console.log(target); var guess; do { guess = Math.floor(Math.random() * 11); console.log(guess); } while (guess;== target);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM