I am a new learner in coding, and i can’t figure out how to make this true and false game work. if it is possible can someone help me with making a keycode ‘t’ for true and keycode ‘f’ for false? thanks!
String myText;
int totalWrong = 0;
int totalCorrect = 0;
int question = 0;
String correctAnswer;
String WrongAnswer;
int True= totalCorrect++;
int False= totalWrong++;
void setup() {
size(800, 800);
fill(0);
myText = "Welcome to the Quiz Game";
textSize(40);
}
void draw() {
background(255);
//Set up the screen for the user.
text("", 0, 300, 800, 700);
text(question, 20, 80);
text("Correct:", 600, 40);
text(totalCorrect, 620, 80);
text("Incorrect:", 600, 140);
text(totalWrong, 620, 180);
//Display the user input text
text(myText, 50, 650);
//OPTIONAL: To improve your code: maybe make a "displayQuestion function.
// ---------------------------SET UP THE QUIZ HERE -----------------------------
if (question ==0) {
//Intro
//Put some user facing (external) documentation here.
text("Press Enter to Begin", 50, 250, 700, 250);
correctAnswer = "";
}
else if (question == 1){
text("Question:lightning never strikes in the same place twice. True or False?", 50, 250, 700, 250);
correctAnswer = "False";
}
else if (question == 2){
text("Question: if you cry in space, the tears just stick onto your face. True or False?", 50, 250, 700, 250);
correctAnswer = "True";
}
else if (question == 3){
text("Question: If you cut an earthworm in half, both halves can regrow their body. True or False? ", 50, 250, 700, 250);
correctAnswer = "False";
}
else if (question == 4){
text("Question: Humans can distinguish between over a trillion different smells. True or False?", 50, 250, 700, 250);
correctAnswer = "True";
}
else if (question == 5){
text("Question: Adults have fewer bones than babies do. True or False?", 50, 250, 700, 250);
correctAnswer = "True";
}else if (question == 6){
text("Question: Goldfish only have a memory span of 3 seconds.True or False?", 50, 250, 700, 250);
correctAnswer = "False";
}else if (question == 7){
text("Question: there are more cells of bacteria in your body than there are human cells.True or False?", 50, 250, 700, 250);
correctAnswer = "True";
}else if (question == 8){
text("Question: Your fingernails and hair keep growing after you die. True or False?", 50, 250, 700, 250);
correctAnswer = "False";
}else if (question == 9){
text("Question: Water spirals down the plughole in opposite directions in the northern and southern hemispheres.True or False?", 50, 250, 700, 250);
correctAnswer = "False";
}else if (question == 10){
text("Question: Humans can't breathe and swallow at the same time. True or False?", 50, 250, 700, 250);
correctAnswer = "True";
}else if (question == 4){
text("Question: A penny dropped from a skyscraper can reach sufficient velocity to kill a pedestrian below. True or False?", 50, 250, 700, 250);
correctAnswer = "False";
}
else{
text("You are done!", 50,250,700,250);
text("You got " + totalCorrect + " correct answers.", 50,300,700,250);
}
//---------------------------------------------------------------------------
}
//Use this function to enter text into the myText string.
void keyPressed() {
if (keyCode == BACKSPACE) {
if (myText.length() > 0) {
myText = myText.substring(0, myText.length()-1);
}
} else if (keyCode == DELETE) {
myText = "";
} else if ( keyCode == ENTER) {
//What happens when you press ENTER
checkAnswer(myText, correctAnswer);
myText = "";
} else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) {
myText = myText + key;
}
else if (keyCode == 't'){
totalCorrect++;
}else if (keyCode == 'f'){
totalWrong++;
}
}
void checkAnswer(String answer, String correctAnswer) {
answer = answer.toLowerCase();
correctAnswer = correctAnswer.toLowerCase();
if (question!=0) {
//Note: You could use .contains() instead.
if (answer.equals(correctAnswer)) {
totalCorrect++;
} else {
totalWrong++;
}
}
question++;
}