【发布时间】:2017-11-02 02:38:36
【问题描述】:
好的,所以我正在尝试为初级作业制作一个小的 Javascript 拼图,而且我只使用过文本框中的数字检查,如果这看起来有点愚蠢,请原谅。
无论如何,我想做的是检查一个文本框中的某个单词,你可以输入密码,以进入下一个“级别”
我的代码:
var timesClicked = 100;
//Function to run the window alert a certain amount of times, as well as hide a certain answer
function changeFunc() {
if (timesClicked > 0){
if (timesClicked == 50) {
window.alert("N34T");
timesClicked--;
changeFunc();
}
else {
window.alert("NEAT");
timesClicked--;
changeFunc();
}
}
else{
window.alert("Sorry, no more answers may be dispensed at this time!");
}
}
//Function to go to the next puzzle
function nextPuzzle(){
if (document.getElementById('answer').value.indexOf("N34T") > -1) {
window.alert("Good Job");
window.location.href="puzzle02.html";
}
}
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="puzzle01.js">
</script>
<title>Puzzle 1</title>
</head>
<header>
<h1>Puzzle 1!</h1>
<p> Please enjoy this puzzle's easiness, they will get harder!</p><br>
</header>
<body>
<p>
<input type="text" id="answer">
<button type="button" onclick="nextPuzzle()">Next Puzzle</button><br><br>
<button type="button" onclick="changeFunc()">Answers!</button>
</p>
</body>
</html>
此声明:
if (document.getElementById('answer').value.indexOf("N34T") > -1)
不会在文本框中使用正确的单词运行。
有人可以帮忙吗?感谢任何可以提前提供帮助的人!
【问题讨论】:
标签: javascript html function if-statement textbox