所以我有一些代码,一旦它完成了一个问题,它停止了无论如何,一旦你选择一个问题,并完成问题和正确地做它会继续到数组中的下一个问题,但是如果你弄错了,它会停下来。我想让它在数组中的下一个元素在一个JavaScript测验
我也有一个小bug,当你在一个问题数量进入,垃圾邮件Enter键就进入到阵列
上质疑0如果你能帮助请做的,在此先感谢。我11岁,在一年前开始编程。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Are you smarter than a 5th Grader?!!</title>
<link rel="stylesheet" href="style.css">
</head>
<body onload="starter()" bgcolor="lightblue">
<h1><marquee><font color="red">Make Trivia Great Again!</font>
</marquee></h1>
<h2><em><center>Are You Smater Than a 5th Grader?</center></em></h2>
<button onclick="sc()">Start</button><br>
<p id="demo"> </p>
<div id="result"></div>
<button onclick="reset()">Reset Score</button>
<script>
function starter(){
setTimeout("clickCounter()",100)
setTimeout("minusCounter()",101)}
function reset(){
setTimeout("clickCounter()",100)
localStorage.clickcount=-1
}
function clickCounter() {
if(typeof(Storage) !== "undefined") {
if (localStorage.clickcount) {
localStorage.clickcount = Number(localStorage.clickcount)+1;
} else {
localStorage.clickcount = 0;
}
document.getElementById("result").innerHTML = "Score:"+
localStorage.clickcount
} else {
} }
function minusCounter(){
if(typeof(Storage) !== "undefined") {
if (localStorage.clickcount) {
localStorage.clickcount = Number(localStorage.clickcount)-1;
} else {
localStorage.clickcount = 0;
}
document.getElementById("result").innerHTML = "Score:"+
localStorage.clickcount
} else {
}
}
if (!("scramble" in Array.prototype)) {
Object.defineProperty(Array.prototype, "scramble", {
enumerable: false,
value: function() {
var o, i, ln = this.length;
while (ln--) {
i = Math.random() * (ln + 1) | 0;
o = this[ln];
this[ln] = this[i];
this[i] = o;
}
return this;
}
});
}
var quiz = [{
"question": ["Bug in the editor"],
"choices": ["Please Ignore,Spam Enter or enter Cancel or Other"],
"correct": ["Other"]
}, {
"question": "Who is the founder of Microsoft?",
"choices": ["Bill Gates", "Steve Jobs", "Steve Wozniak" , "Martin
Shaba"],
"correct": "Bill Gates"
}, {
"question": "What was your first dream?",
"choices": ["8 bits", "64 bits", "1024 bits"],
"correct": "8 bits"
}, {
"question": "The C programming language was developed by?",
"choices": ["Brendan Eich", "Dennis Ritchie", "Guido van
Rossum"],
"correct": "Dennis Ritchie"
}, {
"question": "What does CC mean in emails?",
"choices": ["Carbon Copy", "Creative Commons", "other"],
"correct": "Carbon Copy"
}, {
"question": "What is the full for of IP",
"choices": ["Internet provider", "Intenet Port",
"Other","Internet Protocol"],
"correct": "Carbon Copy"
}]
function stop(){
alert("stopped")
}
function sc(){
quiz.forEach(q => q.choices.scramble());
var x = prompt("Select Start question number #:");
if (x>=6){
alert("please pick a valid question")
sc()
}
else if (x<=5&&x>0){
}
else if(x=0){
alert("please pick a valid question")
sc()
}
else{alert("Please pick a valid question"),sc()}
var ans = ""
function myFunction(item, index) {
ans += "\n[" + (index+1) + "]: " + item ;
}
quiz[x].choices.forEach(myFunction);
var y = prompt(quiz[x].question+"\nYour anwser is:"+ans);
if (y == quiz[x].correct){
alert("Correct!")
clickCounter()
}
else if(y=="Cancel"){alert("canceled")}
else{
alert("Wrong! Please Try Again.");
repeat()
}
function repeat(){
quiz.forEach(q => q.choices.scramble());
var ans = ""
function myFunction(item, index) {
ans += "\n[" + (index+1) + "]: " + item ;
}
quiz[x].choices.forEach(myFunction);
var y = prompt(quiz[x].question+"\nYour anwser is:"+ans);
if (y == quiz[x].correct){
alert("Correct!,Good Job")
clickCounter()
}
else if(y=="Cancel"){alert("canceled")}
else{
alert("Sorry! \nThe right answer is "+quiz[x].correct);
}
}
}
</script>
</body>
</html>
其评论无回答 – geminiousgoel
他可能没有足够的代表发表评论。 – kazenorin
是的,我没有足够的声望评论:( –