U4Ch1L7:2023.2024_Emoji Movie App.

 

// 1️⃣ Step One
// Declare & initialize the question and answer variables below.
// PURPOSE: To create the questions and answers for our quiz game!

var question1 = "🦇🤵";
var question2 = "🏹👩";
var question3 = "👻🚫";
var question4 = "🦁👑";

var answer1 = "BATMAN";
var answer2 = "THE HUNGER GAMES";
var answer3 = "GHOSTBUSTERS";
var answer4 = "THE LION KING";

//Other variables used in the app
var score = 0; // Tracks the user's score
var turn = 1; // Which question to display
var finalMessage = ""; // Final message depending on score
var yourCodeHere; // Used to show you where you must update code

/********************************************************************/

setScreen("titleScreen");

onEvent("startButton", "click", function( ) {
setScreen("quizScreen");
setText("emojiText", question1);
});

 

onEvent("submitAnswer", "click", function( ) {

// 3️⃣ Step Three
// Code your conditional below.
// PURPOSE: To assign a value to correctAnswer based on which round it is.
var userGuess = getText("userGuess"); // User guess from text input box
var correctAnswer; // Correct answer based on quiz round

if (turn == 1){
correctAnswer = answer1;
} else if (turn == 2) {
correctAnswer = answer2;
} else if (turn == 3) {
correctAnswer = answer3;
} else {
correctAnswer = answer4;
}

// 4️⃣ Step Four
// Code your conditional below.
// PURPOSE: To update the score variable
if (userGuess == correctAnswer) {
score = score + 1;
}

// 2️⃣ Step Two
// Code your conditional below
// PURPOSE: To update the question displayed on the screen, and to update turn.

setText("userGuess", ""); // Reset the user input box to be blank

if (turn == 1){
turn = turn + 1; // update turn
setText("emojiText", question2); // update question displayed
} else if (turn == 2) {
turn = turn + 1;
setText("emojiText", question3);
} else if (turn == 3) {
turn = turn + 1;
setText("emojiText", question4);
} else {
setScreen("resultsScreen"); // Quiz is over!
}

// 5️⃣ Step Five
// Code your conditional below
// PURPOSE: Create a unique finalMessage based on the user's score
if (score == 4){
finalMessage = "Perfect!";
} else if (score == 3) {
finalMessage = "Very Good";
} else if (score == 2) {
finalMessage = "Solid work";
} else {
finalMessage = "Better luck next time!";
}

// Create the conditional structure yourself here!

setText("resultsText", score); // Display the score
setText("finalMessageText", finalMessage); // Display the finalMessage
});

onEvent("resetQuizButton", "click", function( ){
score = 0;
resultString = "";
finalMessage = "";
turn = 1;
setText("userGuess", "");
setScreen("titleScreen");
});