U4Ch1L7: 2023.2024_Code Feed Quiz

var result1 = 0;
var result2 = 0;
var result3 = 0;
var result4 = 0;

setScreen("homeScreen");
setUpTheQuiz();

// 1️⃣
// Code a set of conditionals to score answers based on which button the user clicks
function questionOne(userAnswer){
if (userAnswer == "a"){
result1 = result1 + 1;
} else if (userAnswer == "b"){
result2 = result2 + 1;
} else if (userAnswer == "c"){
result3 = result3 + 1;
} else {
result4 = result4 + 1;
}
setScreen("questionTwoScreen");
}

function questionTwo(userAnswer){
if (userAnswer == "a"){
result1 = result1 + 1;
} else if (userAnswer == "b"){
result2 = result2 + 1;
} else if (userAnswer == "c"){
result3 = result3 + 1;
} else {
result4 = result4 + 1;
}
setScreen("questionThreeScreen");
}

function questionThree(userAnswer){
if (userAnswer == "a"){
result1 = result1 + 1;
} else if (userAnswer == "b"){
result2 = result2 + 1;
} else if (userAnswer == "c"){
result3 = result3 + 1;
} else {
result4 = result4 + 1;
}
setScreen("resultsScreen");
finalResults();
}

function finalResults(){

// 2️⃣
// Create the conditional statement that creates the final result strings and the result image

// 3️⃣
// Create an "Easter Egg" conditional that will display a special result if the user
// clicks a specific set of choices.

if (result1 > result2 && result1 > result3 && result1 > result4){
setProperty("resultsTextOne", "text", "You are Kernelator!");
setProperty("resultsTextTwo", "text", "Armed with the astonishing power of Rapid Replication, Kernelator can create countless copies of themselves to form a mighty maize army. This cob combatant tirelessly defends the world from chaos, popping up wherever injustice rears its head.");
setProperty("resultsImage", "image", "//images.code.org/c916747b277225eef22224346a433872-final1.png");
} else if (result2 > result1 && result2 > result3 && result2 > result4){
setProperty("resultsTextOne", "text", "You are Tomatitán!");
setProperty("resultsTextTwo", "text", "Possessing the extraordinary power of Antioxidant Aura, Tomatitán can neutralize harmful free radicals in the environment, protecting both humans and nature from unseen dangers. This juicy juggernaut fearlessly squashes all threats, keeping the world fresh and safe.");
setProperty("resultsImage", "image", "//images.code.org/bae14bf60beacf37b7a8bcdecbdb187a-final4.png");
} else if (result3 > result1 && result3 > result2 && result3 > result4){
setProperty("resultsTextOne", "text", "You are Carrotron!");
setProperty("resultsTextTwo", "text", "Wielding the incredible power of Vitamin Infusion, Carrotron can rejuvenate and heal those around them, spreading health and vitality with just a touch. This crunchy crusader always roots out evil and nourishes justice.");
setProperty("resultsImage", "image", "//images.code.org/4b4abeca6a233cd5dae00180aa851ca6-final2.png");
} else {
setProperty("resultsTextOne", "text", "You are Brocca!");
setProperty("resultsTextTwo", "text", "From the fabled Garden of Greens, Brocca can instantly boost the strength and abilities of allies by sharing their nutrient-rich essence. This floret fighter steams evildoers with ease.");
setProperty("resultsImage", "image", "//images.code.org/4105de514533553a452a7409f5f75c51-final3.png");
}
}

function setUpTheQuiz(){

// 4️⃣
// Customize the quiz to make it your own!

setProperty("quizSubjectTextbox", "text", "If you were a superhero, and also a vegetable, what might you be?");
setProperty("question1", "text", "What is your favorite texture?");
setProperty("answer1a", "text", "Velvety Smooth");
setProperty("answer1b", "text", "Rough and Tumble");
setProperty("answer1c", "text", "Itch-tastic");
setProperty("answer1d", "text", "Bumpy and bulbous");
setProperty("image1a", "image", "//images.code.org/6886e5aa15bf6f4f912ce92297318bb2-velvet.png");
setProperty("image1b", "image", "//images.code.org/48f878eb0e4711e2c94520e428e662ee-rough.png");
setProperty("image1c", "image", "//images.code.org/aede40113f1545db507e1365551b0af8-itchy.png");
setProperty("image1d", "image", "//images.code.org/1cd3783d932b2a572b7586b8b7ddf9dd-bumpy.png");

setProperty("question2", "text", "What is your favorite flavor?");
setProperty("answer2a", "text", "Buttery");
setProperty("answer2b", "text", "Sweet");
setProperty("answer2c", "text", "Savory");
setProperty("answer2d", "text", "Salty");
setProperty("image2a", "image", "//images.code.org/dd6f2d13224c20505fd223875f92bc96-buttery.png");
setProperty("image2b", "image", "//images.code.org/97ad25b9ce37a1516da388a14ada1a63-sweet.png");
setProperty("image2c", "image", "//images.code.org/11ac94f610c403433f1d74bd875d4bb6-savory.png");
setProperty("image2d", "image", "//images.code.org/25f69aed5df8759eb97d9f543b7bb0e5-salty.png");

setProperty("question3", "text", "If you were a car, which one would you be?");
setProperty("answer3a", "text", "El Camino");
setProperty("answer3b", "text", "Box Truck");
setProperty("answer3c", "text", "Lamborghini");
setProperty("answer3d", "text", "Ford Pinto");
setProperty("image3a", "image", "//images.code.org/fbb9692c9afcae1e8e80378b156a4d2f-elCamino2.png");
setProperty("image3b", "image", "//images.code.org/448d5a0315f9017fcdc6c9812f66fd69-boxTruck.png");
setProperty("image3c", "image", "//images.code.org/f5b84513fb9866aedcf5c1a50ea24039-lambo.png");
setProperty("image3d", "image", "//images.code.org/90f9e80c7cf95dcecf6d1a4bc7f56166-elCamino.png");

// corn: //images.code.org/c916747b277225eef22224346a433872-final1.png
// tomato: //images.code.org/bae14bf60beacf37b7a8bcdecbdb187a-final4.png
// carrot: //images.code.org/4b4abeca6a233cd5dae00180aa851ca6-final2.png
// broccoli: //images.code.org/4105de514533553a452a7409f5f75c51-final3.png
}

onEvent("startButton", "click", function( ) {
setScreen("questionOneScreen");
});

onEvent("resetQuizButton", "click", function( ) {
result1 = 0;
result2 = 0;
result3 = 0;
result4 = 0;
setScreen("homeScreen");
});

// EVENT HANDLERS FOR BUTTON CLICKS
// ******** QUESTION ONE ****************
onEvent("button1a", "click", function( ) {
questionOne("a");
});

onEvent("button1b", "click", function( ) {
questionOne("b");
});

onEvent("button1c", "click", function( ) {
questionOne("c");
});

onEvent("button1d", "click", function( ) {
questionOne("d");
});

// ******** QUESTION TWO ****************
onEvent("button2a", "click", function( ) {
questionTwo("a");
});

onEvent("button2b", "click", function( ) {
questionTwo("b");
});

onEvent("button2c", "click", function( ) {
questionTwo("c");
});

onEvent("button2d", "click", function( ) {
questionTwo("d");
});

// ******** QUESTION THREE ****************
onEvent("button3a", "click", function( ) {
questionThree("a");
});

onEvent("button3b", "click", function( ) {
questionThree("b");
});

onEvent("button3c", "click", function( ) {
questionThree("c");
});

onEvent("button3d", "click", function( ) {
questionThree("d");
});