0% found this document useful (0 votes)
18 views4 pages

Component A

The document outlines a JavaScript program for a quiz application that tests users on identifying cats based on images and names. It includes functionality for filtering data, updating screens, checking answers, and managing scores. The program also allows users to navigate between quiz screens and reset their progress.

Uploaded by

tjia033
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views4 pages

Component A

The document outlines a JavaScript program for a quiz application that tests users on identifying cats based on images and names. It includes functionality for filtering data, updating screens, checking answers, and managing scores. The program also allows users to navigate between quiz screens and reset their progress.

Uploaded by

tjia033
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

//Lists from the data or filtered

var idsList = getColumn("Cats", "id");


var namesList = getColumn("Cats", "Name");
var imagesList = getColumn("Cats", "Image");
var names1List = [];
var names2List = [];
var images1List = [];
var images2List = [];
//Variables created
var score = 0;
var index = -1;
var nindex1 = 1;
var nindex2 = 1;
var right = -1;
var wrong = 0;
var correct = "";
//Filtering the namesList and imagesList with idsList
for(var i=0;i<namesList.length;i++) {
var names = namesList[i];
var ids = idsList[i];
var images = imagesList[i];
if(ids >= 33) {
appendItem(names2List, names);
appendItem(images2List, images);
} else{
appendItem(names1List, names);
appendItem(images1List, images);
}
}
//Sets screen to quiz 1 when "quiz1Button" is pressed
onEvent("quiz1Button", "click", function() {
setScreen("quiz1");
});
//Sets screen to quiz 2 when "quiz2Button is pressed
onEvent("quiz2Button", "click", function() {
setScreen("quiz2");
});
//Hides "start1" and shows "submit1" when "start1" is pressed
onEvent("start1", "click", function() {
updateScreen1();
hideElement("start1");
showElement("submit1");
});
//Gives a arguement for the parameter checkAnwser1
onEvent("submit1", "click", function() {
checkAnswer1(getText("answer1"));
});
//Hides "start2" and shows "submit2" when "start2" is pressed
onEvent("start2", "click", function() {
updateScreen2();
hideElement("start2");
showElement("submit2");
});
//Gives a arguement for the parameter checkAnwser2
onEvent("submit2", "click", function() {
checkAnswer2(getText("answer2"));
});
//Updates the screen by setting the questio and image and keeping track of your score.
function updateScreen1 () {
setText("question1", "Is this a " + names1List[nindex1 = randomNumber(right = right +
1, wrong = wrong + 1)] + "?");
setImageURL("catImage1", images1List[index = index + 1]);
if (score == 5) {
setScreen("scoreboard");
}
}
//Updates the screen by setting the questio and image and keeping track of your score.
function updateScreen2 () {
setText("question2", "Is this a " + names2List[nindex2 = randomNumber(right = right +
1, wrong = wrong + 1)] + "?");
setImageURL("catImage2", images2List[index = index + 1]);
if (score == 5) {
setScreen("scoreboard");
}
}
//Procedure will check if the anwser is true or false and check if the question and image
matches or not and give a score or give a hint for the user
//Arguement: string
function checkAnswer1 (answer) {
if(index == nindex1 && answer == "True") {
updateScreen1 ();
score = score + 1;
}else if(index != nindex1 && answer == "False") {
updateScreen1 ();
score = score + 1;
}else {
for(var i = 0;i<names1List.length;i++){
var names = names1List[i];
if(i == index){
correct = names;
}
}
setText("question1", "Try Agian! It's a " + correct + "!");
}
}
//Procedure will check if the anwser is true or false and check if the question and image
matches or not and give a score or give a hint for the user
//Arguement: string
function checkAnswer2 (answer) {
if(index == nindex2 && answer == "True") {
updateScreen2 ();
score = score + 1;
}else if(index != nindex2 && answer == "False") {
updateScreen2 ();
score = score + 1;
}else {
for(var i = 0;i<names2List.length;i++){
var names = names2List[i];
if(i == index){
correct = names;
}
}
setText("question2", "Try Agian! It's a " + correct + "!");
}
}
//Resets the variable values and takes the user back to "homescreen"
onEvent("playAgian", "click", function() {
setScreen("homescreen");
score = 0;
index = -1;
nindex1 = 1;
nindex2 = 1;
right = -1;
wrong = 0;
correct = "";
});

You might also like