Question: I need to get this javascript program up and running ASAP! HTML Code
I need to get this javascript program up and running ASAP!
HTML Code
The Raider Trivia Game!
We know Raider trivia...
Do you??? Well, let's see!!!
--------------------------------------------------------------------------------------------------
.jumbotron {background-color: #A9A9A9;}
div {margin-bottom: 20px; font-family: 'Sans-Serif', serif; font-size: 1.25em;}
.correct, .incorrect {text-transform: capitalize;}
body {
background-image: url("http://www.finewebstores.com/thumbnail.asp?file=assets/images/teamarearugs/nflarearugs/repeatrugs/oakland-raiders-rug.jpg&maxx=300&maxy=0");
}
App.js
//Pseudocode for Raider Trivia Game
//Display questions with a timer
// display options
//capture results
//evaluate result for correct or incorrect
// update counter for right and wrong answer
// dispaly results
// repeat the above till all questions run out
// display final result
// options to restart game
// varibales i need
// hold the questions
$.fn.trivia = function() { //$ binds a function to the document.ready event.
var ThisThing = this; //identifies the choice selected
ThisThing.userPick = null; // capturs the select answer
ThisThing.answers = { //keeps track of the result
correct: 0,
incorrect: 0
};
ThisThing.images = null; //
ThisThing.count = 30; // timer for answer countdown
ThisThing.current = 0; // start array for the question
ThisThing.questions = [ {
question: "Who is the Raiders all-time scoring leader ? ",
choices: ["Sebastian Janikowski", "George Blanda", "Tim Brown", "Jerry Rice"],
correct: 0
}, { // object for questions - target 10 questions ..
question: "Which Raider won the Heisman, Super Bowl MVP and NFL MVP? ",
choices: ["Tim Brown", "Dave Casper", "Kenny Stabler", "Marcus Allen"],
correct: 0
},
{
question: "Which Raider QB has won the most Super Bowls?",
choices: ["Jim Plunkett", "Kenny Stabler", "Rich Gannon", "Rusty Hilger"],
correct: 2
},
{
question: "Which Raider WR is the all-time receptions leader?",
choices: ["Jerry Rice", "Cliff Branch", "Fred Biletnikoff", "Warren Wells "],
correct: 2
},
{
question: "What was the original name of the Raiders?",
choices: ["Gladiators", "Invaders", "Senors", "Regulators"],
correct: 0
},
{
question: "Raider head coach with multiple Super Bowl Wins?",
choices: ["John Madden", "Al Davis", "Jon Gruden", "Tom Flores"],
correct: 3
},
{
question: "Only Raider to be on all 3 Super Bowl winning teams?",
choices: ["Lester Hayes", "Cliff Branch", "Howie Long", "Jack Tatum"],
correct: 1
},
{
question: "Which player went on to lead the NFLPA? " ,
choices: ["George Atkinson", "Matt Millen", "Ted Hendricks", "John Matusak"],
correct: 0
},
];
ThisThing.ask = function() {
if (ThisThing.questions[ThisThing.current]) { //
$("#timer").html("Time remaining: " + "00:" + ThisThing.count + " secs");
$("#question_div").html(ThisThing.questions[ThisThing.current].question);
var choicesArr = ThisThing.questions[ThisThing.current].choices;
var buttonsArr = [];
for (var i = 0; i < choicesArr.length; i++) {
var button = $('
button.text(choicesArr[i]);
button.attr('data-id', i);
$('#choices_div').append(button);
}
window.triviaCounter = setInterval(ThisThing.timer, 1000); // countdown in one sec intervals
} else {
$('.card-body').append($('
', {
text: 'Unanswered: ' + (
ThisThing.questions.length - (ThisThing.answers.correct + ThisThing.answers.incorrect)),
class: 'result'
}));
$('#start_button').text('Restart').appendTo('.card-body').show();
}
};
ThisThing.timer = function() { //
ThisThing.count--; // countdown from 20 seconds
if (ThisThing.count <= 0) {
setTimeout(function() { // Display an alert box after ThisThing.next + 1000 (in ThisThing.next func) :
ThisThing.nextQ();
});
} else {
$("#timer").html("Time remaining: " + "00:" + ThisThing.count + " secs");
}
};
ThisThing.nextQ = function() {
ThisThing.current++;
clearInterval(window.triviaCounter); //stops the timer
ThisThing.count = 30;
$('#timer').html("");
setTimeout(function() {
ThisThing.cleanUp();
ThisThing.ask();
}, 3000)
};
ThisThing.cleanUp = function() {
$('div[id]').each(function(item) {
$(this).html('');
});
$('.correct').html('Correct answers: ' + ThisThing.answers.correct);
$('.incorrect').html('Incorrect answers: ' + ThisThing.answers.incorrect);
};
ThisThing.answer = function(correct) {
var string = correct ? 'correct' : 'incorrect';
ThisThing.answers[string]++;
$('.' + string).html(string + ' answers: ' + ThisThing.answers[string]);
};
return ThisThing;
};
// Trivia Function ends
var Trivia;
$("#start_button").click(function() {
$(this).hide();
$('.result').remove();
Trivia = new $(window).trivia();
Trivia.ask();
});
$('#choices_div').on('click', 'button', function(e) {
var userPick = $(this).data("id"),
ThisThing = Trivia || $(window).trivia(),
index = ThisThing.questions[ThisThing.current].correct,
correct = ThisThing.questions[ThisThing.current].choices[index];
if (userPick !== index) {
$('#choices_div').text("Wrong Answer! The correct answer was: " + correct);
ThisThing.answer(false);
} else {
$('#choices_div').text("Correct!!! The correct answer was: " + correct);
ThisThing.answer(true);
}
ThisThing.nextQ();
});
Question bank.js
ThisThing.questions = [ {
question: "Who is the Raiders all-time scoring leader ? ",
choices: ["Sebastian Janikowski", "George Blanda", "Tim Brown", "Jerry Rice"],
correct: 0
}, {
// object for questions - target 5 questions ..
question: "Which Raider won the Heisman, Super Bowl MVP and NFL MVP? ",
choices: ["Tim Brown", "Dave Casper", "Kenny Stabler", "Marcus Allen"],
correct: 0
}, {
question: "Which Raider QB has won the most Super Bowls?",
choices: ["Jim Plunkett", "Kenny Stabler", "Rich Gannon", "Rusty Hilger"],
correct: 2
},
{
question: "Which Raider WR is the all-time receptions leader?",
choices: ["Jerry Rice", "Cliff Branch", "Fred Biletnikoff", "Warren Wells "],
correct: 2
},
{
question: "What was the original name of the Raiders?",
choices: ["Gladiators", "Invaders", "Senors", "Regulators"],
correct: 0
},
{
question: "Raider head coach with multiple Super Bowl Wins?",
choices: ["John Madden", "Al Davis", "Jon Gruden", "Tom Flores"],
correct: 3
},
{
question: "Only Raider to be on all 3 Super Bowl winning teams?",
choices: ["Lester Hayes", "Cliff Branch", "Howie Long", "Jack Tatum"],
correct: 1
},
{
question: "Which vitamin is considered to be a hormone? Vitamin - " ,
choices: ["D", "A", "C", "B12"],
correct: 2
},
];