Я пытаюсь написать простую викторину.Привет всем - Java Script Quiz
Я хочу, чтобы создать массив вопросов, передать его в петлю и распечатать окончательный ответ через переменную, которая будет вычислять 20 марок за каждый правильный ответ.
function Myfunction() {
var y = ["q0",
"q1",
"q2",
"q3",
"q4"];
for (i = 0; i <= y.length; i++) {
var x = document.getElementById(y[i]).value("correct");
var score = x * 20;
alert("Your score is" & "score");
break;
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Welcome to your Web Quiz</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="robots" content="index,follow" />
<link rel="stylesheet" type="text/css" href="quiz.css" />
<form>
<h1>
Quiz about corporate crap
</h1>
<div class="questions">
What's the difference between a boss and a manager?
<ul><input type="radio" id="q0" value="correct">Boss is a boss</ul>
<ul><input type="radio" id="q0" value="False">Manager is a manager</ul>
<ul><input type="radio" id="q0" value="False">Both are blah </ul>
</div>
<br>
<div class="questions">
What's the right thing to do?
<br>
<ul><input type="radio" id="q1" value="correct">Do what the boss says </ul>
<ul><input type="radio" id="q1" value="False">Do what the bosses boss says</ul>
<ul><input type="radio" id="q1" value="False">Dont give a fuck do what you want to do</ul>
</div>
<br>
<div class="questions">
Listen to your heart is that good advice?
<ul><input type="radio" id="q2" value="correct">Listen to it, do not execute</ul>
<ul><input type="radio" id="q2" value="False">Shove it up your a#$$</ul>
<ul><input type="radio" id="q2" value="False"> Shove it up some one elses a$#$</ul>
<br>
</div>
<div class="questions">
<br>
Who is a client?
<ul><input type="radio" id="q3" value="correct">Someone whose astrological charts are right</ul>
<ul><input type="radio" id="q3" value="False">Who gets payed to screw around</ul>
<ul><input type="radio" id="q3" value="False">Someone who is arrogant about being stupid and proud about it </ul>
</div>
<br>
<br>
<br>
<input type="button" value="I am done" align="center" onsubmit= "Myfunction()">
</form>
</head>
<body>
</body>
</html>
Я бы начал с размещения вашего фактического html ** не ** в голове и в ** body **. oh и rtfm тоже :) –