var Question = function(id, text, correct, incorrect){
this.id = id;
this.text = text;
this.all = incorrect;
this.all.push(correct);
this.all.sort(randomSort);
}
Question.prototype.write = function(){
var qu = document.getElementById("questions");
qu.innerHTML += "<p>" + this.text + "</p>";
var questionList = "<ul class='questionlist'>";
for (var i = 0; i < this.all.length; i++) {
if (this.all[i] == this.correct) {
questionList += "<li><input type='checkbox' name='" + this.id + "'>" + this.all[i] + "</input></label></li>";
}
else {
questionList += "<li><input type='checkbox' name='" + this.id + "'>" + this.all[i] + "</input></label></li>";
}
}
questionList += "</ul>";
qu.innerHTML += questionList;
}
var randomSort = function(a, b){
return Math.random() * 100 - 50;
}
var q1 = new Question("q1", "Which of these cities has been around the longest?", "Athens", ["Krakow", "London", "Rome"]);
var q2 = new Question("q2", "What city is nearest the equator?", "London", ["Amsterdam", "Berlin", "Warsaw"]);
var q3 = new Question("q3", "What is the capital of Peru?", "Lima", ["Ancash", "Cusco", "La Paz"]);
var q4 = new Question("q4", "As of 2010 which is the most populated city?", "Tokyo", ["Sao Paolo", "Los Angeles", "London"]);
var questions = [q1, q2, q3, q4].sort(randomSort);
for (var i = 0; i < 3; i++) {
questions[i].write();
questions.splice(rnd)
}
function load() {
var load = window.open('cw2.htm','','scrollbars=yes,menubar=yes,height=600,width=600,resizable=yes,toolbar=no,l ocation=no,status=no');
}
Quiz
1.)This writes a random question to the page and provides a check box, however i would like to be able to provide immediate feedback, for example, when they check the box I can display in writing weather what they chose was wrong
2.) My function down the bottom opens a new windows with another new question, however the question somtimes repeats I need to somehow keep the questions random, the .sort math random function does this, but as im loading in a new window the JS starts over again and so arrays already been used are back in
Any help would be much aprreciated. I know I am brand new just looking for a lifeline