Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
I am trying to do a game where there is a map with levels and on each level there is a question, if you answer the question correctly the button will change its color to green else red. But I don't know how to make the code do the same but with different answers.
This are the questions and answers:
1.Who wrote one of his sonatas entirely at night and so called it the "Moonlight Sonata"? (Beethoven)

2.He was fond of incorporating the numbers 14 and 41 into his musical works, because they were derived from the mystical numerology values of the letters in his own name? (Bach)

3. He wrote his first opera, Mitridate Re di Ponto, in 1770 when he was only 14 years old? (Mozart)

4. His music is known for its humor? (Haydn)



Choose and type your answer:                               
A - Sebastian Bach            
B - Joseph Haydn                
C - Beethoven                      
D - Amadeus Mozart

What I have tried:

//Map game
function Game_Question() {
var choice = prompt("Enter a Choice");
getText("Answer_text1");
if (choice == "C") {
setProperty("button_Qlevel1", "background-color", "green");
} else {
setProperty("button_Qlevel1", "background-color", "red");
}
if (choice == "A") {
setProperty("button_Qlevel2", "background-color", "green");
} else {
setProperty("button_Qlevel2", "background-color", "red");
}
if (choice == "D") {
setProperty("button_Qlevel3", "background-color", "green");
} else {
setProperty("button_Qlevel3", "background-color", "red");
}
if (choice == "B") {
setProperty("button_Qlevel4", "background-color", "green");
} else {
setProperty("button_Qlevel4", "background-color", "red");
}
setScreen("GameMapscreen");
Posted
Updated 2-Apr-18 9:44am

1 solution

Make a class that can contain a question, its correct answer, the next level, and the button colour. Then all you need to do is create a List of objects of the class, each with the appropriate values. You then process each object and change the colour and level when the user gives the correct answer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900