我正在创建一个非常简单的程序,它显示英语短语和用户在西班牙语翻译中的类型。语句是这样的:const phrases = { "Hello": "Hola", "Goodbye" : "Adios", //etc...}以及匹配逻辑:Spanish_Phrases.prototype.calculate = function() { this.answer = (document.getElementById("answer").value); var question = $("#question").text(); var questionMatcher = phrases[question].toString(); var answerMatcher = this.answer; if (questionMatcher.ToLowerCase() == answerMatcher.ToLowerCase()) { alert("Correct!") } else { alert("Try again"); }}HTML是这样的:<!DOCTYPE html><html><head> <title>Spanish</title></head><body> <center> <script src="./src/spanish.js"> </script> <link href="skeleton.css" rel="stylesheet"> <section> <h2>Spanish Quiz</h2> <h3 id="question"></h3> <button type="button" id="questionbutton">Get English Phrase</button> <form action="#" id="form" name="form" onsubmit="return false;"> Type Spanish translation...<br> <input id="answer" name="answer" type="text"><br> <br> <input id="submit" type="submit" value="Submit"> </form> </section> </center> <script src="https://code.jquery.com/jquery-3.4.1.min.js"> </script> <script>但是,目前如果用户输入的答案大小写不正确,则将其标记为错误。这就是为什么我尝试使用 'ToLowerCase' 但它说它不是一个函数。我在字符串上使用它,当我在控制台中调试时,它显示它们是刺痛,但这会引发错误。我在我的代码中遗漏了一些完全明显的东西吗?帮助将不胜感激,谢谢!
添加回答
举报
0/150
提交
取消