2017-09-04 32 views
-8

在我的代碼中,「SiAff」不會是正確答案... 我想使用「.toLowerCase」和「.toUpperCase」,但是我不知道該怎麼做。 任何幫助會感激JavaScript中的「Idiot Check」(.toLowerCase和.toUpperCase)

var Que = prompt("What's my name") 

if (Que == "Siaff") { 
    document.write("Correct!") 
} 

else { 
    document.write("Wrong!") 
} 
+3

'Que.toLowerCase()==「siaff'' ...? – deceze

+0

你想實現什麼?代碼應該做什麼? – Cerbrus

+0

歡迎來到SO。請訪問[幫助],看看有什麼和如何問。提示:顯示工作 - 例如google mdn toLowerCase閱讀如何使用toLowerCase - 或者:https://www.google.nl/search?q=how+to+compare+strings+case+insensitive+javascript哪些[返回重複](https://stackoverflow.com/questions/2140627/javascript-case-insensitive-string-comparison)作爲第一個 – mplungjan

回答

1

嘗試這樣Que.toLowerCase()

var Que = prompt("What's my name") 
 

 
if (Que.toLowerCase() === "siaff") { 
 
    document.write("Correct!") 
 
} 
 

 
else { 
 
    document.write("Wrong!") 
 
}

+0

'===',而不是'==' – Cerbrus

+2

@Cerbrus :它使上面的零差異完全一致。 –

+2

還是一個好習慣。 – Cerbrus