我做了一个法语测验,但它没有用。
以下是代码:
<html>
<head>
<title>Quiz</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>Quiz</h1>
<p id="one"></p>
<input id="aone" />
<br>
<a href="#" class="myButton" id="btn">Mark It</a>
<script>
var verbs = ["accompagner","aider","aimer","apporter","chanter","danser","coûter","écouter","étudier","fermer","jouer","laver","marcher","montrer","oublier","passer","penser","préparer","raconter","agir","bâtir","choisir","désobéir","finir","guérir","nourrir","obéir","punir","réfléchir","remplir","réussir","rougir","saisir","attendre","défendre","descendre","entendre","interrompre","perdre","rendre","répondre","rompre","vendre"];
var verb = verbs[Math.floor(Math.random() * verbs.length)];
if(verb.slice(-2) == "er") {
var newverb = verb.substring(0, verb.length - 2);
newverb += "es";
}
if(verb.slice(-2) == "ir") {
var newverb = verb.substring(0, verb.length - 2);
newverb += "is";
}
if(verb.slice(-2) == "re") {
var newverb = verb.substring(0, verb.length - 2);
newverb += "s";
}
document.getElementById("one").innerHTML = verb;
document.getElementById("btn").onclick = function () {
if (document.getElementById("aone").value==newverb) { // Not Working.
alert("Correct");
}
}
</script>
</body>
</html>
我认为我已经将问题追溯到最终的if
声明并不是真的,但我不明白为什么。
所有帮助将不胜感激。
答案 0 :(得分:0)
由于它是用另一种语言,它真的不清楚你要做什么。
但是,您的条件有效。我添加了alert()
,以便您可以看到“newverb”等于什么。
如果在输入字段中添加了已提醒的值,则条件将起作用。