简体   繁体   English

如何使用大写/小写

[英]How to use Upper/Lower case

Hey So I had a code like this嘿所以我有一个这样的代码

const answer = "HA"

const answers = answer.toLowerCase();

const theanswer = document.getElementById("WIT").value;

if(theanswer == answers) {
console.log("correct")
}

the thing is if the correct only showed up if I type "ha"问题是只有当我输入“ha”时才会出现正确的

How can i make the correct showed if I type "HA" or "Ha" or "hA" or "ha"如果我输入“HA”或“Ha”或“hA”或“ha”,我怎样才能做出正确的显示

To compare the values - convert the value to lowerCase as well - for example - try typing "ha" into the input.要比较这些值 - 也将值转换为小写 - 例如 - 尝试在输入中键入“ha”。

On the first charachrer - "h" - you will log "h: incorrect" and then on the "a" it will log "ha: correct".在第一个字符 - “h” - 您将记录“h:不正确”,然后在“a”上记录“ha:正确”。 ay other character s will obviously not match the "HA" and will be incorrect.任何其他字符 s 显然与“HA”不匹配,并且是不正确的。

 const answer = "HA" const answers = answer.toLowerCase(); document.querySelector('#WIT').addEventListener('keyup', checkMe) function checkMe(){ const theanswer = document.getElementById("WIT").value; if(theanswer.toLowerCase() == answers) { console.log(theanswer + ": correct") } else { console.log(theanswer + ": incorrect") } }
 <input type="text" id="WIT" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM