我的自我教育進展緩慢,我遇到了問題。我試圖從用戶那裏獲得文本輸入。然後,我希望該輸入是針對自身的大寫版本進行檢查的。我通過labs.codecademy.com運行代碼(如果這是相關的)。string.toUpperCase困難
代碼:
function rollerInput() {
var input = prompt("Do you want to reroll? You have " + rerolls + " rerolls left. Y/N?");
input = input.toUpperCase;
if(input === null) {
console.log("Please enter Y or N");
rollerInput();
} else if(input === "") {
console.log("Please enter Y or N");
rollerInput();
} else if(input === "Y" && rerolls !== 1) {
rerolls = rerolls -1;
reRoller();
} else if(input === "Y" && rerolls === 1) {
console.log("You have no rerolls left.");
}
}
問題在於與檢查Y或N.無論ÿ或y產生任何反應的IFS。我確信我錯過了一些簡單的東西,但我無法修復它以挽救我的生命。
這是一個方法,你必須用括號把它稱爲'()':'輸入= input.toUpperCase();' – vikingmaster 2014-09-22 21:00:55
@GregHewgill&SterlingArcher的感謝!我的錯。 – 2014-09-22 22:16:42