YouTube Quiz
Details of my YouTube Quiz
Initial Idea
My Quiz was based on the extremely popular video sharing website known as YouTube. It contains 3 multiple-choice questions.
Bold = correct answer
Q1: What is the most disliked video on YouTube?
A: Everyday Bro B: So Sorry C: YouTube Rewind 2018 D: Egg Video
Q2: Where does the first video on YouTube take place?
A: Eiffel Tower B: San Diego Zoo C: Statue of Liberty D: Bronx Zoo
Q3: What is the most viewed video on YouTube?
A: Gangnam Style B: Baby Shark C: Hello D: Despacito
My Original Code
This is what I used to first start my quiz. It worked well but it didn't have a "Incorrect" screen that it redirected to if there was a question that was answered incorrectly. It was also not efficient. It had a "onEvent" block for every possible answer so it was messy and inefficient.
var score = 0;
var question = 0;
console.log(score);
console.log("question: " + question);
onEvent("StartButton", "click", function(change_screen) {
setScreen("Question1Screen");
question = question + 1;
});
onEvent("Dislike1", "click", function() {
setScreen("Question2Screen");
});
onEvent("Dislike2", "click", function() {
setScreen("Question2Screen");
});
onEvent("Dislike3", "click", function() {
setScreen("Question2Screen");
score = score + 1;
console.log(score);
question = question + 1;
});
onEvent("Dislike4", "click", function() {
setScreen("Question2Screen");
});
onEvent("Viewed1", "click", function() {
setScreen("Question3Screen");
});
onEvent("Viewed2", "click", function() {
setScreen("finalscreen");
score = score + 1;
console.log(score);
question = question + 1;
setText("text_area2", "You answered " + (score + "/3 questions correctly!"));
});
onEvent("Viewed3", "click", function() {
setScreen("Question3Screen");
});
onEvent("Viewed4", "click", function() {
setScreen("Question3Screen");
});
onEvent("Question2Answers", "change", function( ) {
var Question2answer = getText("Question2Answers");
if (Question2answer == "The San Diego Zoo") {
score = score + 1;
setScreen("Question3Screen");
console.log(score);
question = question + 1;
} else {
setScreen("finalscreen");
console.log(score);
question = question + 1;
}
});
My Final Code
This is my final code. I added some If/Else Statements to get rid of most of the clutter. I also added Incorrect Screens for when you get a question wrong.
order = ["Question1Screen", "Question2Screen", "Question3Screen", "finalscreen"]
// Functions
function Incorrect_Next_Question() {
onEvent("nextquestion", "click", function( ) {
questions = questions + 1;
setScreen(order[questions])
});
}
// Variables
var questions = 0
var score = 0;
console.log(score);
onEvent("StartButton", "click", function(change_screen) {
setScreen("Question1Screen");
// Question 1 Code
onEvent("Dislike3", "click", function( ) {
setScreen("Question2Screen");
score = score + 1;
console.log(score);
order = order + 1;
});
onEvent("Dislike1", "click", function() {
setScreen("IncorrectScreen");
Incorrect_Next_Question()
});
onEvent("Dislike2", "click", function( ) {
setScreen("IncorrectScreen");
Incorrect_Next_Question()
});
onEvent("Dislike4", "click", function( ) {
setScreen("IncorrectScreen");
Incorrect_Next_Question()
});
// Question 2 Code
onEvent("Question2Answers", "change", function( ) {
var Question2answer = getText("Question2Answers");
if (Question2answer == "The San Diego Zoo") {
score = score + 1;
setScreen("Question3Screen");
order = order + 1;
console.log(score);
} else {
setScreen("IncorrectScreen");
Incorrect_Next_Question()
console.log(score);
}
});
// Question 3 Code
onEvent("Viewed2", "click", function( ) {
setScreen("finalscreen");
score = score + 1;
if (score == 3) {
setText("Encouragement", "Wow, you got a perfect score!");
} else {
if (score == 2) {
setText("Encouragement", "Almost there. Keep trying to get 3/3!");
} else {
if (score <= 1) {
setText("Encouragement", "Oops, I think you made a few mistakes.");
}
}
}
console.log(score);
setText("text_area2", "You answered " + (score + "/3 questions correctly!"));
});
onEvent("Viewed1", "click", function() {
setScreen("finalscreen");
setText("text_area2", "You answered " + (score + "/3 questions correctly!"));
if (score == 3) {
setText("Encouragement", "Wow, you got a perfect score!");
} else {
if (score == 2) {
setText("Encouragement", "Almost there. Keep trying to get 3/3!");
} else {
if (score <= 1) {
setText("Encouragement", "Oops, I think you made a few mistakes.");
}
}
}
});
onEvent("Viewed3", "click", function( ) {
setScreen("finalscreen");
setText("text_area2", "You answered " + (score + "/3 questions correctly!"));
if (score == 3) {
setText("Encouragement", "Wow, you got a perfect score!");
} else {
if (score == 2) {
setText("Encouragement", "Almost there. Keep trying to get 3/3!");
} else {
if (score <= 1) {
setText("Encouragement", "Oops, I think you made a few mistakes.");
}
}
}
});
onEvent("Viewed4", "click", function( ) {
setScreen("finalscreen");
setText("text_area2", "You answered " + (score + "/3 questions correctly!"));
if (score == 3) {
setText("Encouragement", "Wow, you got a perfect score!");
} else {
if (score == 2) {
setText("Encouragement", "Almost there. Keep trying to get 3/3!");
} else {
if (score <= 1) {
setText("Encouragement", "Oops, I think you made a few mistakes.");
}
}
}
});
});