Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*var questions = [{
- "question" : "Insert question 1 here",
- "option1" : "Answer 1",
- "option2" : "Answer 2",
- "option3" : "Answer 3",
- "option4" : "Answer 4",
- "answer" : "2",
- }, {
- "question" : "Insert question 2 here",
- "option1" : "Answer 1",
- "option2" : "Answer 2",
- "option3" : "Answer 3",
- "option4" : "Answer 4",
- "answer" : "3",
- }, {
- "question" : "Insert question 3 here",
- "option1" : "Answer 1",
- "option2" : "Answer 2",
- "option3" : "Answer 3",
- "option4" : "Answer 4",
- "answer" : "4",
- }, {
- "question" : "Insert question 4 here",
- "option1" : "Answer 1",
- "option2" : "Answer 2",
- "option3" : "Answer 3",
- "option4" : "Answer 4",
- "answer" : "1",
- }];
- var currentQuestion = 0;
- var score = 0;
- var totQuestions = questons.length;
- var container = document.getElementById('quizContainer');
- var questionEl = document.getElementById('question');
- var opt1 = document.getElementById('opt1');
- var opt2 = document.getElementById('opt2');
- var opt3 = document.getElementById('opt3');
- var opt4 = document.getElementById('opt4');
- var nextButton = document.getElementById ('nextButton');
- var resultCont = document.getElementById ('result');
- function loadQuestion (questionIndex) {
- var q = questions [questionIndex];
- questionEl.textContent = (questionIndex + 1) + '. '+ q.question;
- opt1.textContent = q.option1;
- opt2.textContent = q.option2;
- opt3.textContent = q.option3;
- opt4.textContent = q.option4;
- };
- function loadNextQuestion () {
- var selectedOption = document.querySelector('input[type=radio]:checked');
- if (!selectedOption){
- alert('Please select your answer');
- return;
- }
- var answer = selectedOption.value;
- if (questions[currentQuestion].answer == answer){
- score += 10;
- }
- selectedOption.checked = false;
- currentQuestion++;
- if(currentQuestion == totQuestions -1{
- nextButton.textContent = 'Finish';
- }
- if(currentQuestion == totQuestions){
- container.style.display = 'none';
- resultCont.style.display = '';
- resultCont.textContent = 'Your Score: ' + score;
- return;
- }
- loadQuestion(currentQuestion);
- }
- loadQuestion(currentQuestion); */
- var questions = [{
- "question" : "For what use was Youtube originally created for?",
- "option1" : "Gaming videos",
- "option2" : "Memes",
- "option3" : "Educational videos",
- "option4" : "A dating site",
- "answer" : "4",
- }, {
- "question" : "What is the most searched tutorial on youtube?",
- "option1" : "how to tame a dragon",
- "option2" : "How to kiss",
- "option3" : "How to make a bird house",
- "option4" : "how to make chicken nuggets",
- "answer" : "2",
- }, {
- "question" : "The most disliked video on youtube is?",
- "option1" : "Despacito",
- "option2" : "PewdiePie plays Amnesia",
- "option3" : "Justin Biebers baby",
- "option4" : "Logan paul finds a dead body",
- "answer" : "3",
- }, {
- "question" : "When was the youtube domain name registerd?",
- "option1" : "Valentine’s Day in 2005",
- "option2" : "Christmas in 2001",
- "option3" : "April fools day in 2003",
- "option4" : " 7 December 1997",
- "answer" : "1",
- }, {
- "question" : "How much does a avarage user visit youtube a month?",
- "option1" : "14 times",
- "option2" : "28 times",
- "option3" : "50 times",
- "option4" : "100 times",
- "answer" : "1",
- }, {
- "question" : "What is the most watched non music video on youtube?",
- "option1" : "The legend of tiny knuckles",
- "option2" : "YLYL #9",
- "option3" : "Charlie bit my finger",
- "option4" : "The onision rant",
- "answer" : "3",
- }, {
- "question" : "Who created youtube",
- "option1" : "Chad Hurley",
- "option2" : "Steve Chen",
- "option3" : "Jawed Karim",
- "option4" : "All three of themm",
- "answer" : "4",
- }, {
- "question" : "How much does an avarage user use youtube a hour?",
- "option1" : "48 hours",
- "option2" : "12 hours",
- "option3" : "5 hours",
- "option4" : "1 hour",
- "answer" : "1",
- }, {
- "question" : "For how much did google buy youtube",
- "option1" : "12 american dollars",
- "option2" : "They just stole it!",
- "option3" : "1.65 Billion",
- "option4" : "12.5 million",
- "answer" : "3",
- }, {
- "question" : "How much time would you need to watch all the youtube content",
- "option1" : "1,700 years",
- "option2" : "13 years and 5 days",
- "option3" : "100 years",
- "option4" : "a full week without sleeping",
- "answer" : "1",
- }];
- var appContainer = document.getElementById('cont'),
- questionEl = document.getElementById('question'),
- opt1 = document.getElementById('opt1'),
- opt2 = document.getElementById('opt2'),
- opt3 = document.getElementById('opt3'),
- opt4 = document.getElementById('opt4'),
- nxtBtn = document.getElementById('next'),
- result = document.getElementById('result'),
- currentQuestion = 0,
- totQuestions = questions.length,
- score = 0;
- function loadQuestion(questionIndex) {
- 'use strict';
- var q = questions[questionIndex];
- questionEl.textContent = (questionIndex + 1) + '. ' + q.question;
- opt1.textContent = q.option1;
- opt2.textContent = q.option2;
- opt3.textContent = q.option3;
- opt4.textContent = q.option4;
- }
- function loadNextQuestion() {
- 'use strict';
- var selectedOption = document.querySelector('input[type=radio]:checked'),
- answer;
- if (!selectedOption) {
- alert('Please Select Your Answer');
- return;
- }
- answer = selectedOption.value;
- if (questions[currentQuestion].answer === answer) {
- score += 10;
- }
- selectedOption.checked = false;
- currentQuestion += 1;
- if (currentQuestion === totQuestions - 1) {
- nxtBtn.textContent = 'Finish';
- }
- if (currentQuestion === totQuestions) {
- appContainer.style.display = 'none';
- result.style.display = '';
- result.textContent = 'Your Score: ' + score;
- return;
- }
- loadQuestion(currentQuestion);
- }
- loadQuestion(currentQuestion);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement