# True and false keycodes for game (Quiz / true or false game)

**URL:** https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884
**Category:** Coding Questions
**Created:** [November 27, 2019, 3:40pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884 "2019-11-27T15:40:19Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Zayba](https://avatars.discourse-cdn.com/v4/letter/z/43a26b/32.png) [@Zayba](https://discourse.processing.org/u/Zayba)
#### Post date: [November 27, 2019, 3:40pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/1 "2019-11-27T15:40:19Z")

</div>

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!

```auto
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++;
}

```

---

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [November 27, 2019, 5:08pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/2 "2019-11-27T17:08:14Z")

</div>

Please format your Code correctly, and please refrase your question to make it clear what you‘re having problems with.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 27, 2019, 5:23pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/3 "2019-11-27T17:23:23Z")

</div>

Hey, and welcome to the forum!

Great to have you here!

Please learn how to post code

This is making a keycode ‘t’ for true and keycode ‘f’ for false

But you need to check whether true or false is the correct answer for this current question

Chrisir

```auto

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 (key == 't') {
    println("t");
    totalCorrect++;
    checkAnswer(myText, correctAnswer);
  } else if (key == 'f') {
    totalWrong++;
    checkAnswer(myText, correctAnswer);
  } else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) {
    myText = myText + key;
  }
}

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++;
}
//

```

---

<div class="post-metadata">

### Author: ![Zayba](https://avatars.discourse-cdn.com/v4/letter/z/43a26b/32.png) [@Zayba](https://discourse.processing.org/u/Zayba)
#### Post date: [November 27, 2019, 9:27pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/4 "2019-11-27T21:27:10Z")

</div>

Need a piece of code where keycode ‘t’ is equal to true and ‘f’ is equal to false. And also if the questions answer is equal to false, and the f keycode is pressed, they should get one correct answer but if they press the t keycode, they should get one wrong in the game, and vice versa.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 27, 2019, 9:39pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/5 "2019-11-27T21:39:56Z")

</div>

Hey, Zayba, this description is much better than what you had before.

I showed you how to read f and t.

And I put `totalCorrect++;` there what was just placeholder really.

Replace it with something like

```auto
if ( correctAnswer.equals("False") )
   totalCorrect++;
else totalWrong++;

```

and for ‘t’ the other way round

Then show your entire code

Chrisir

---

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [November 28, 2019, 11:13am UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/6 "2019-11-28T11:13:38Z")

</div>

Btw, the Code has an error at the last question, where (question == 4 ) is a duplicate.

---

<div class="post-metadata">

### Author: ![Zayba](https://avatars.discourse-cdn.com/v4/letter/z/43a26b/32.png) [@Zayba](https://discourse.processing.org/u/Zayba)
#### Post date: [November 28, 2019, 3:12pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/7 "2019-11-28T15:12:25Z")

</div>

```auto
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 == 11) {

    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 (key == 't') {
    println("t");
    totalCorrect++;
    checkAnswer(myText, correctAnswer);
  } else if (key == 'f') {
    totalWrong++;
    checkAnswer(myText, correctAnswer);
  } else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) {
    myText = myText + key;
  }
}

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)) {

      if ( correctAnswer.equals("False") )
   totalCorrect++;
else totalWrong++;
    }else{
      if ( correctAnswer.equals("True") )
   totalCorrect++;
else totalWrong++;

      totalWrong++;
    }
  }
  question++;
}
//

```

this is my code now, but there is still something wrong it because when I press key-code ‘f’, or ‘t’, the score jumps by 1 or 2 for each of the scores.

 ![zayba4](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a8364f16caf454f3fd0fb7403f275580dce0b3d3.png) ![zayba4|690x462]

---

<div class="post-metadata">

### Author: ![Zayba](https://avatars.discourse-cdn.com/v4/letter/z/43a26b/32.png) [@Zayba](https://discourse.processing.org/u/Zayba)
#### Post date: [November 28, 2019, 3:13pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/8 "2019-11-28T15:13:31Z")

</div>

![zayba5](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/41c1a0e9bf0d66b2bfd860e01a5819d463d008be.png)

---

<div class="post-metadata">

### Author: ![Zayba](https://avatars.discourse-cdn.com/v4/letter/z/43a26b/32.png) [@Zayba](https://discourse.processing.org/u/Zayba)
#### Post date: [November 28, 2019, 3:14pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/9 "2019-11-28T15:14:06Z")

</div>

![zayba6](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/2666e2762e78d2ef004645ab0bdf24f20cc01e64.png)

---

<div class="post-metadata">

### Author: ![Zayba](https://avatars.discourse-cdn.com/v4/letter/z/43a26b/32.png) [@Zayba](https://discourse.processing.org/u/Zayba)
#### Post date: [November 28, 2019, 3:14pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/10 "2019-11-28T15:14:56Z")

</div>

![zayba7](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e1a5712a955b7ea4676486049899e1ccf87826a1.png)

---

<div class="post-metadata">

### Author: ![Zayba](https://avatars.discourse-cdn.com/v4/letter/z/43a26b/32.png) [@Zayba](https://discourse.processing.org/u/Zayba)
#### Post date: [November 28, 2019, 4:00pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/11 "2019-11-28T16:00:04Z")

</div>

Never mind, i figured out how to get the scores to go up by one, but if the answer to question one is false, and i press the ‘f’ key then the counter adds one to the incorrect group instead of the correct answer group. And vice versa. I really appreciate the help!

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 28, 2019, 4:49pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/12 "2019-11-28T16:49:53Z")

</div>

Did you post the last / current version of the Sketch or is the above version old?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 28, 2019, 5:10pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/13 "2019-11-28T17:10:20Z")

</div>

> [@Zayba](#):
>
> ```auto
> if (answer.equals(correctAnswer)) {
> 
> if ( correctAnswer.equals("False") )
> 
> ```
> 
> totalCorrect++;  
> else totalWrong++;  
> }else{  
> if ( correctAnswer.equals(“True”) )  
> totalCorrect++;  
> else totalWrong++;
> 
> ```auto
> totalWrong++;
> }
> 
> ```
> 
> }

Maybe your problem lies in these lines.

Can you check whether they are correct?

Please, in processing hit **ctrl-t** to get auto-format

---

<div class="post-metadata">

### Author: ![Zayba](https://avatars.discourse-cdn.com/v4/letter/z/43a26b/32.png) [@Zayba](https://discourse.processing.org/u/Zayba)
#### Post date: [November 29, 2019, 3:03pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/14 "2019-11-29T15:03:43Z")

</div>

```auto
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 == 11) {

    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 (key == 't') {
    println("t");
    totalCorrect++;
    checkAnswer(myText, correctAnswer);
  } else if (key == 'f') {
    totalWrong++;
    checkAnswer(myText, correctAnswer);
  } else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) {
    myText = myText + key;
  }
}

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)) {

      if ( correctAnswer.equals("False") )
        totalCorrect++;
      else totalWrong++;
    } else {
      if ( correctAnswer.equals("True") )
        totalCorrect--;
      else totalWrong--;

      totalWrong=0+1;
    }
  }
  question++;
}
//

```

this is my most recent code

---

<div class="post-metadata">

### Author: ![Zayba](https://avatars.discourse-cdn.com/v4/letter/z/43a26b/32.png) [@Zayba](https://discourse.processing.org/u/Zayba)
#### Post date: [November 29, 2019, 3:15pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/15 "2019-11-29T15:15:59Z")

</div>

i tried what you suggested, Chrisir, but the same problem pops up.

 ![zayba10](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/768d56d322109f28a4ccae2cf23360f047d01783.png)

---

<div class="post-metadata">

### Author: ![Zayba](https://avatars.discourse-cdn.com/v4/letter/z/43a26b/32.png) [@Zayba](https://discourse.processing.org/u/Zayba)
#### Post date: [November 29, 2019, 3:17pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/16 "2019-11-29T15:17:14Z")

</div>

![zayba11%20](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f369929689f3f3cdc51b4221707a58be9d8379a8.png)

---

<div class="post-metadata">

### Author: ![Zayba](https://avatars.discourse-cdn.com/v4/letter/z/43a26b/32.png) [@Zayba](https://discourse.processing.org/u/Zayba)
#### Post date: [November 29, 2019, 3:17pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/17 "2019-11-29T15:17:58Z")

</div>

![zayba12](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/d0f3c717b195b3a727e843d35e47b18d2eb46cd4.png)

---

<div class="post-metadata">

### Author: ![Zayba](https://avatars.discourse-cdn.com/v4/letter/z/43a26b/32.png) [@Zayba](https://discourse.processing.org/u/Zayba)
#### Post date: [November 29, 2019, 3:18pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/18 "2019-11-29T15:18:39Z")

</div>

![zayba13](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a3b08c338c2d4e0b6dc97c6defc58f878219aae5.png)

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 29, 2019, 4:08pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/19 "2019-11-29T16:08:52Z")

</div>

can somebody please check this, I don’t have time

---

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [November 29, 2019, 4:55pm UTC](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884/20 "2019-11-29T16:55:42Z")

</div>

Remove the incrementing in the keyPressed t and f functions. Generally, what are they used for? If you press enter, if the answer is right you get correctAnswer++, but if you press t and give in the wrong answer, you get correctAnswer++ and wrongAnswer++… you shouldn‘t set correctAnswer++, only because the t key is pressed.

Im assuming you intended to go with t for true and f for false as an answer and somewhere decided to have people write the answer out as a text and then decide wether it‘s the correct answer, but you can‘t use both at the same time (that just doesn’t make much sense, though you could technically do it…).

Im not sure how clear i‘m being right now, but in short, in KeyPressed, remove the correctAnswer++; and falseAnswer++; within the key = ‚t‘ and key = ‚f‘ parts. They cause the wrong values.

Note, i couldn‘t get the Code to run on IOS, so i can‘t tell if that solves it, but i think it should, if there‘s not another issue.

[Next page](https://discourse.processing.org/t/true-and-false-keycodes-for-game-quiz-true-or-false-game/15884.md?page=2)
