Created
June 21, 2017 23:38
-
-
Save arbianchi/a8446614d706dd98715b74993eeedbd1 to your computer and use it in GitHub Desktop.
Trivia Game Feedback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ADINA: This structure works but a constructor object would help you avoid repeating code. It would look something like this: | |
// var questions = []; | |
// function question(question, answers, correctAnswer) { | |
// this.question = question; | |
// this.answers = answers; | |
// this.correctAnswer = correctAnswer; | |
// questions.push(this); | |
// } | |
// var q1 = new question("Who was the team’s coach in the 1999-2000 season?",["Dean Smith", "Bill Guthridge", "Matt Doherty", "Roy Williams"]); | |
var questions = [ | |
{ | |
question: "Who was the team’s coach in the 1999-2000 season?", | |
answers: ["Dean Smith", "Bill Guthridge", "Matt Doherty", "Roy Williams"], | |
correctAnswer: 1 | |
}, { | |
question: "What is the name of the UNC mascot?", | |
answers: ["Tar Heel", "Jordan", "Ramses", "Wallace"], | |
correctAnswer: 2 | |
}, { | |
question: "How many NCAA national championships has UNC won?", | |
answers: [4, 5, 6, 7], | |
correctAnswer: 2 | |
}, { | |
question: "What NBA team drafted Michael Jordan when he left UNC in 1984?", | |
answers: ["Houston Rockets", "Portland Trail Blazers", "Detroit Pistons", "Chicago Bulls"], | |
correctAnswer: 3 | |
}, { | |
question: "Where did Roy Williams coach before going to UNC?", | |
answers: ["Kansas", "Kentucky", "Kent State", "Kansas State"], | |
correctAnswer: 0 | |
}]; | |
var intervalId; | |
var clockRunning; | |
// Nice! | |
var timer = { | |
time: 15, | |
start: function() { | |
if (!clockRunning) { | |
intervalId = setInterval(timer.count, 1000); | |
clockRunning = true; | |
} | |
}, | |
stop: function() { | |
clearInterval(intervalId); | |
clockRunning = false; | |
}, | |
count: function() { | |
timer.time--; | |
$("#timer").html(timer.time); | |
} | |
}; | |
var userChoice; | |
var numberRight; | |
var numberWrong; | |
var unanswered; | |
var currentQuestion; | |
var answerMessage; | |
var correctResponse; | |
var answerImage; | |
$("#start").click(function(){ | |
$("#start").hide(); | |
for (var i = 0; i < questions.length; i++) { | |
timer.start; | |
$("#question").html(questions[i].question); | |
for (var j = 0; j < questions[i].answers.length; j++) { | |
var option = questions[i].answers[j]; | |
// ADINA: appendTo doesn't exist. You want .append | |
$('<li><input type="radio" value=' + j + ' name="dynradio" />' + option + '</li>').appendTo$("#answers"); | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment