Coding help with questions

I’ve been trying (for a while now) to add in a fill in the blank type question into my quiz but whenever I try to add in the specified code for the fill in the blank type of question: the code doesn’t work together with the code for the other questions.
Is there a way to separate the code for the fill in the blank question from the code for the multiple choice and true/false?

(i removed the images for convenience sake of helping me)

Code:


int score =0; //score
int screen =0; //screen
PImage img; //cpu image
PImage ww; //world war 1 tenches image
String s="";


void setup () {
  size(1500, 1000);
}
//splash screen

void draw() {
  background(#0099FC);//blue
  if (screen == 0) {
    fill(255);//white
    textSize(26); 
    text("Welcome to the quiz,", 20, 50);
    text("in this quiz you will be tested on your general knowledge of different school subjects", 20, 90);
    text("along with your knowledge of Computer Science", 20, 130);
    text("Press the any key on your keyboard to continue :)", 400, 500);
  }
  //screen 1
  if (screen == 1) {
    background(#02A54C); //green
    textSize(30); 
    text("Question 1:", 20, 80);
    text("What is this computer part?", 20, 140);
    scale(0.7);//cpu image
    //image(img, 800, 60);
    strokeWeight(4);
    fill(#FCBB52); //yellow
    //Question boxes
    rect(0, 900, 900, 220);
    rect(900, 900, 920, 220);
    rect(0, 1120, 900, 220);
    rect(900, 1120, 920, 220);
    fill(0);
    textSize(80);
    //questions
    text("1)", 40, 1000); //answer
    text("2)", 950, 1000);
    text("3)", 40, 1220);
    text("4)", 950, 1220);
    text("CPU", 140, 1000);
    text("RAM", 1050, 1000);
    text("GPU", 140, 1220);
    text("HardDrive", 1050, 1220);
    text(score, 1450, 100);
    text("/12", 1500, 100);
  }
  if (screen == 2) {
    background(#FF4000); //orange
    textSize(60);
    text(score, 1100, 100);
    //Question boxes
    textSize(40);
    text("Question 2:", 25, 100);
    text("When did the first World War start?", 25, 160);
    fill(#FCBB52);
    //questions
    rect(0, 650, 660, 150);
    rect(660, 650, 710, 150);
    rect(0, 800, 660, 150);
    rect(660, 800, 710, 150);
    fill(0);
    textSize(60);
    text("1)", 40, 715);//Questions
    text("2)", 700, 715);
    text("3)", 40, 865);
    text("4)", 700, 865);
    text("1900", 120, 715);
    text("1914", 780, 715);
    text("1984", 120, 865);
    text("1918", 780, 865);
    scale(1.3);
    // image(ww, 500, 140);
    textSize(40);
    text("/12", 875, 75);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == '1') || (key == '!'))) {
      delay(300);// only add 1 score
      score++;
    }
  }

  if (screen ==3) {
    background(#08BC87);
    textSize(60);
    fill(0);
    text(score, 1100, 100);
    textSize(40);
    text("Question 3:", 25, 100);
    text("This is RAM.", 25, 160);  
    //  image(RAM, 500, 100);
    fill(#1BBF48);
    rect(0, 650, 750, 250);
    fill(#ED182A);
    rect(660, 650, 750, 250);
    fill(0);
    textSize(100);
    text("T)", 50, 800);
    text("True", 160, 800);
    text("F)", 720, 800);
    text("False", 830, 800);
    textSize(50);
    text("/12", 1135, 100);


    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == '2') || (key == '@'))) {
      delay(300);
      score++;
    }
  }
  if (screen ==4) {
    text("Question 4:", 25, 100);
    text("What part is this?", 25, 160);  
    fill(#FCBB52);
    rect(0, 640, 660, 160);
    rect(660, 640, 700, 160);
    rect(0, 800, 660, 160);
    rect(660, 800, 700, 160);
    fill(0);
    text("1)", 40, 715);//Questions
    text("2)", 700, 715);
    text("3)", 40, 865);
    text("4)", 700, 865);
    text("PSU", 120, 715);
    text("SSD", 780, 715);
    text("HDD", 120, 865);
    text("GPU", 780, 865);
    fill(0);
    text("/12", 1135, 100);
    scale(1.6);
    //image(gpu, 300, 100);
    textSize(80);
    text("/12", 1135, 100);
    textSize(40);
    text(score, 680, 70);

    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == 't') || (key == 'T'))) {
      delay(300);
      score++;
    }
  }
  if (screen ==5) {

    background(#4030FC);
    text("Question 5:", 25, 100);
    text("Linux is the most popular OS", 25, 160);
    fill(#1BBF48);
    rect(0, 650, 750, 250);
    fill(#ED182A);
    rect(660, 650, 750, 250);
    fill(0);
    textSize(100);
    text("T)", 50, 800);
    text("True", 160, 800);
    text("F)", 720, 800);
    text("False", 830, 800);
    scale(0.9);
    //image(L, 500, 200);


    textSize(60);
    text("/12", 1135, 100);
    textSize(60);
    text(score, 1100, 100);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == '4') || (key == '$'))) {
      delay(300);
      score++;
    }
  }
  if (screen ==6) {
    background(#575BBF);
    fill(0);
    text("Question 5:", 25, 100);
    text("What does SSD stand for?", 25, 160);
    fill(#FCBB52);
    rect(0, 640, 660, 160);
    rect(660, 640, 700, 160);
    rect(0, 800, 660, 160);
    rect(660, 800, 700, 160);
    fill(0);
    text("1)", 40, 715);//Questions
    text("2)", 700, 715);
    text("3)", 40, 865);
    text("4)", 700, 865);
    textSize(44);
    text("Hard Disk Drive", 120, 715);
    text("Solid State Drive", 780, 715);
    text("Graphics Processing Unit", 120, 865);
    text("Central Processing unit", 780, 865);
    scale(0.8);
    text("/12", 1135, 100);
    textSize(60);
    text(score, 1100, 100);
    scale(0.8);
    //image(ssd, 500, 100);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == 'f') || (key == 'F'))) {
      delay(300);
      score++;
    }
  }

  if (screen ==7) {
    background(#0CAA4C);
    fill(0);
    text("Question 6:", 25, 100);
    text("A SSD is slower than a HDD.", 25, 160);
    fill(#1BBF48);
    rect(0, 650, 750, 250);
    fill(#ED182A);
    rect(660, 650, 750, 250);
    fill(0);
    textSize(100);
    text("T)", 50, 800);
    text("True", 160, 800);
    text("F)", 720, 800);
    text("False", 830, 800);
    textSize(60);
    text("/12", 1135, 100);
    textSize(60);
    text(score, 1100, 100);
    scale(0.5);
    //image(hdd, 500, 280);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == '2') || (key == '@'))) {
      delay(300);
      score++;
    }
  }

  if (screen ==8) {
    background(#571CC6);
    text("Question 7:", 25, 100);
    text("Which Countries flag is this?", 25, 160);
    fill(#FCBB52);
    rect(0, 640, 660, 160);
    rect(660, 640, 700, 160);
    rect(0, 800, 660, 160);
    rect(660, 800, 700, 160);
    fill(0);
    text("1)", 40, 715);//Questions
    text("2)", 700, 715);
    text("3)", 40, 865);
    text("4)", 700, 865);
    text("Vietnam", 120, 715);
    text("Spain", 780, 715);
    text("Philippines", 120, 865);
    text("Denmark", 780, 865);
    textSize(60);
    text("/12", 1135, 100);
    textSize(60);
    text(score, 1100, 100);
    scale(0.6);
    //image(flag, 500, 320);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == 'f') || (key == 'F'))) {
      delay(300);
      score++;
    }
  }

  if (screen ==9) {
    background(#C68F1E);
    text("Question 8:", 25, 100);
    text("A calculator is a computer", 25, 160);
    fill(#1BBF48);
    rect(0, 650, 750, 250);
    fill(#ED182A);
    rect(660, 650, 750, 250);
    fill(0);
    textSize(100);
    text("T)", 50, 800);
    text("True", 160, 800);
    text("F)", 720, 800);
    text("False", 830, 800);
    textSize(60);
    text("/12", 1135, 100);
    textSize(60);
    text(score, 1100, 100);
    scale(0.3);
    //image(calc, 500, 700);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == '1') || (key == '!'))) {
      delay(300);
      score++;
    }
  }
  if (screen ==10) {
    background(#0C550F);
    textSize(30);
    text("Question 9:", 25, 100);
    text("Alexander Graham Bell inveted the light bulb.", 25, 160);
    fill(#1BBF48);
    rect(0, 650, 750, 250);
    fill(#ED182A);
    rect(660, 650, 750, 250);
    fill(0);
    textSize(100);
    text("T)", 50, 800);
    text("True", 160, 800);
    text("F)", 720, 800);
    text("False", 830, 800);
    //image(light, 500, 200);
    textSize(60);
    text("/12", 1145, 100);
    textSize(60);
    text(score, 1100, 100);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == 't') || (key == 'T'))) {
      delay(300);
      score++;
    }
  }

  if (screen ==11) {
    background(#34B6CE);
    text("Question 9:", 25, 100);
    text("Where is Mount Everest located?.", 25, 160);
    fill(#FCBB52);
    rect(0, 640, 660, 160);
    rect(660, 640, 700, 160);
    rect(0, 800, 660, 160);
    rect(660, 800, 700, 160);
    fill(0);
    text("1)", 40, 715);//Questions
    text("2)", 700, 715);
    text("3)", 40, 865);
    text("4)", 700, 865);
    text("Tibet", 120, 715);
    text("Nepal", 780, 715);
    textSize(30);
    text("Border betweeem Tibet and Nepal", 120, 865);
    text("China", 780, 865);
    fill(0);
    textSize(60);
    text("/12", 1165, 100);
    textSize(60);
    text(score, 1100, 100);
    scale(0.3);
    //image(mount, 600, 600);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == 'f') || (key == 'F'))) {
      delay(300);
      score++;
    }
  }

  if (screen ==12) {
    background(#FFA600);
    fill(0);
    textSize(60);
    text("/12", 1165, 100);
    textSize(60);
    text(score, 1100, 100);
    textSize(40);
    text("Question 11:", 25, 100);    
    text("Mitochandrian is the \"_ _ _ _ _ _ _ _ _ _\"  of the cell", 25, 160);
    fill(255, 255, 0);
    text(s, 240, 120);
  }
  if (screen ==13) {
    background(0);
  }
  if (screen ==12) {
    if (key>='a'&&key<='z') {
      s+=key;
    }
    if (key==ENTER||key==RETURN) {
      if (s.equals("powerhouse")) {
        screen = 13;
      }
      s="";
    }
  }



  //asnwer to previous question adds score if code is in next screen
  if ((keyPressed == true) && ((key == '3') || (key == '#'))) {
    delay(300);
    score++;
  }
}

void keyPressed() {
  if (keyPressed == true && screen >=0) {
    screen = screen + 1;
  }
}

thanks, good formatted code ( and it runs here )

but ends up ( after some key press ) in a black / blue empty picture.

-a- please can you rephrase your question ( fill )
-b- in keyPress you use

 screen = screen + 1;

you should do some check like

if ( screen > 12 ) { //__ final page
//  screen = 0;

}
1 Like

That’s what I’ve been trying to fix, what its supposed to do is stay at the screen where it has the mitochondria question and the user types out an answer relating to the question; but it ends up going to the next screen instead of allowing the user to type in an answer

i figured out the problem was in the keypress section because for the other questions, it just switches to the next screen if the user gets it wrong but i dont want that to be the case but i dont know how to fix it exactly

looks like your keyPressed is the problem,
as you switch to next screen ( at any )
but actually you should do screen++ only after show a win / loose picture

the basic concept should be
++ start________________ screen 0
++ question_____________ screen 1 ( question 1 )
++ check answer_________ screen 2 ( answer 1 )
question ++
++ next question_________ screen 1 ( question 2 )

++ summary score / quit / restart_______ screen 3

so with having screens 0 /1 /2 /3
you want show different questions with possible answers / good answer compare user input / content
that sounds like you need arrays for that?

2 Likes

Yeah, you have 2 main variables: screen and numberOfCurrentQuestion

Then screen goes between ask and show answer back and forth. And doesn‘t grow endlessly.

Instead numberOfCurrentQuestion grows.

You want to extract the data from your code. The questions and 4 answers go into separate arrays that you can define before setup with all questions.
String [] question = {“what is”,
“Who is…”}; etc.
(My “” don’t come out right sometimes)

Then in the code it’s only question[numberOfCurrentQuestion] and
possibleAnswer1[numberOfCurrentQuestion]
possibleAnswer2[numberOfCurrentQuestion]
possibleAnswer3[numberOfCurrentQuestion]
possibleAnswer4[numberOfCurrentQuestion]
correctAnswer[numberOfCurrentQuestion]
etc. - lean and nice!

2 Likes

In this line also say && screen != 12

so that he doesn’t increase the screen in this special screen

Sorry my previous answer was a bit off topic and more a general improvement

1 Like

I’m still super new to processing and code itself (only grade 10) so how I be able to implement that concept into my actual code itself? I’ve been trying for a couple of hours and whenever i get to screen 12 it bugs out and does a bunch of letters instead of letting the user type out their answer for the fill in the blank

In keyPressed() you should also check, in which screen you are


int score =0; //score
int screen =0; //screen
PImage img; //cpu image
PImage ww; //world war 1 tenches image
String s="";


void setup () {
  size(1500, 1000);
}
//splash screen

void draw() {
  background(#0099FC);//blue
  if (screen == 0) {
    fill(255);//white
    textSize(26); 
    text("Welcome to the quiz,", 20, 50);
    text("in this quiz you will be tested on your general knowledge of different school subjects", 20, 90);
    text("along with your knowledge of Computer Science", 20, 130);
    text("Press the any key on your keyboard to continue :)", 400, 500);
  }
  //screen 1
  if (screen == 1) {
    background(#02A54C); //green
    textSize(30); 
    text("Question 1:", 20, 80);
    text("What is this computer part?", 20, 140);
    scale(0.7);//cpu image
    //image(img, 800, 60);
    strokeWeight(4);
    fill(#FCBB52); //yellow
    //Question boxes
    rect(0, 900, 900, 220);
    rect(900, 900, 920, 220);
    rect(0, 1120, 900, 220);
    rect(900, 1120, 920, 220);
    fill(0);
    textSize(80);
    //questions
    text("1)", 40, 1000); //answer
    text("2)", 950, 1000);
    text("3)", 40, 1220);
    text("4)", 950, 1220);
    text("CPU", 140, 1000);
    text("RAM", 1050, 1000);
    text("GPU", 140, 1220);
    text("HardDrive", 1050, 1220);
    text(score, 1450, 100);
    text("/12", 1500, 100);
  }
  if (screen == 2) {
    background(#FF4000); //orange
    textSize(60);
    text(score, 1100, 100);
    //Question boxes
    textSize(40);
    text("Question 2:", 25, 100);
    text("When did the first World War start?", 25, 160);
    fill(#FCBB52);
    //questions
    rect(0, 650, 660, 150);
    rect(660, 650, 710, 150);
    rect(0, 800, 660, 150);
    rect(660, 800, 710, 150);
    fill(0);
    textSize(60);
    text("1)", 40, 715);//Questions
    text("2)", 700, 715);
    text("3)", 40, 865);
    text("4)", 700, 865);
    text("1900", 120, 715);
    text("1914", 780, 715);
    text("1984", 120, 865);
    text("1918", 780, 865);
    scale(1.3);
    // image(ww, 500, 140);
    textSize(40);
    text("/12", 875, 75);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == '1') || (key == '!'))) {
      delay(300);// only add 1 score
      score++;
    }
  }

  if (screen ==3) {
    background(#08BC87);
    textSize(60);
    fill(0);
    text(score, 1100, 100);
    textSize(40);
    text("Question 3:", 25, 100);
    text("This is RAM.", 25, 160);  
    //  image(RAM, 500, 100);
    fill(#1BBF48);
    rect(0, 650, 750, 250);
    fill(#ED182A);
    rect(660, 650, 750, 250);
    fill(0);
    textSize(100);
    text("T)", 50, 800);
    text("True", 160, 800);
    text("F)", 720, 800);
    text("False", 830, 800);
    textSize(50);
    text("/12", 1135, 100);


    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == '2') || (key == '@'))) {
      delay(300);
      score++;
    }
  }
  if (screen ==4) {
    text("Question 4:", 25, 100);
    text("What part is this?", 25, 160);  
    fill(#FCBB52);
    rect(0, 640, 660, 160);
    rect(660, 640, 700, 160);
    rect(0, 800, 660, 160);
    rect(660, 800, 700, 160);
    fill(0);
    text("1)", 40, 715);//Questions
    text("2)", 700, 715);
    text("3)", 40, 865);
    text("4)", 700, 865);
    text("PSU", 120, 715);
    text("SSD", 780, 715);
    text("HDD", 120, 865);
    text("GPU", 780, 865);
    fill(0);
    text("/12", 1135, 100);
    scale(1.6);
    //image(gpu, 300, 100);
    textSize(80);
    text("/12", 1135, 100);
    textSize(40);
    text(score, 680, 70);

    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == 't') || (key == 'T'))) {
      delay(300);
      score++;
    }
  }
  if (screen ==5) {

    background(#4030FC);
    text("Question 5:", 25, 100);
    text("Linux is the most popular OS", 25, 160);
    fill(#1BBF48);
    rect(0, 650, 750, 250);
    fill(#ED182A);
    rect(660, 650, 750, 250);
    fill(0);
    textSize(100);
    text("T)", 50, 800);
    text("True", 160, 800);
    text("F)", 720, 800);
    text("False", 830, 800);
    scale(0.9);
    //image(L, 500, 200);


    textSize(60);
    text("/12", 1135, 100);
    textSize(60);
    text(score, 1100, 100);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == '4') || (key == '$'))) {
      delay(300);
      score++;
    }
  }
  if (screen ==6) {
    background(#575BBF);
    fill(0);
    text("Question 5:", 25, 100);
    text("What does SSD stand for?", 25, 160);
    fill(#FCBB52);
    rect(0, 640, 660, 160);
    rect(660, 640, 700, 160);
    rect(0, 800, 660, 160);
    rect(660, 800, 700, 160);
    fill(0);
    text("1)", 40, 715);//Questions
    text("2)", 700, 715);
    text("3)", 40, 865);
    text("4)", 700, 865);
    textSize(44);
    text("Hard Disk Drive", 120, 715);
    text("Solid State Drive", 780, 715);
    text("Graphics Processing Unit", 120, 865);
    text("Central Processing unit", 780, 865);
    scale(0.8);
    text("/12", 1135, 100);
    textSize(60);
    text(score, 1100, 100);
    scale(0.8);
    //image(ssd, 500, 100);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == 'f') || (key == 'F'))) {
      delay(300);
      score++;
    }
  }

  if (screen ==7) {
    background(#0CAA4C);
    fill(0);
    text("Question 6:", 25, 100);
    text("A SSD is slower than a HDD.", 25, 160);
    fill(#1BBF48);
    rect(0, 650, 750, 250);
    fill(#ED182A);
    rect(660, 650, 750, 250);
    fill(0);
    textSize(100);
    text("T)", 50, 800);
    text("True", 160, 800);
    text("F)", 720, 800);
    text("False", 830, 800);
    textSize(60);
    text("/12", 1135, 100);
    textSize(60);
    text(score, 1100, 100);
    scale(0.5);
    //image(hdd, 500, 280);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == '2') || (key == '@'))) {
      delay(300);
      score++;
    }
  }

  if (screen ==8) {
    background(#571CC6);
    text("Question 7:", 25, 100);
    text("Which Countries flag is this?", 25, 160);
    fill(#FCBB52);
    rect(0, 640, 660, 160);
    rect(660, 640, 700, 160);
    rect(0, 800, 660, 160);
    rect(660, 800, 700, 160);
    fill(0);
    text("1)", 40, 715);//Questions
    text("2)", 700, 715);
    text("3)", 40, 865);
    text("4)", 700, 865);
    text("Vietnam", 120, 715);
    text("Spain", 780, 715);
    text("Philippines", 120, 865);
    text("Denmark", 780, 865);
    textSize(60);
    text("/12", 1135, 100);
    textSize(60);
    text(score, 1100, 100);
    scale(0.6);
    //image(flag, 500, 320);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == 'f') || (key == 'F'))) {
      delay(300);
      score++;
    }
  }

  if (screen ==9) {
    background(#C68F1E);
    text("Question 8:", 25, 100);
    text("A calculator is a computer", 25, 160);
    fill(#1BBF48);
    rect(0, 650, 750, 250);
    fill(#ED182A);
    rect(660, 650, 750, 250);
    fill(0);
    textSize(100);
    text("T)", 50, 800);
    text("True", 160, 800);
    text("F)", 720, 800);
    text("False", 830, 800);
    textSize(60);
    text("/12", 1135, 100);
    textSize(60);
    text(score, 1100, 100);
    scale(0.3);
    //image(calc, 500, 700);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == '1') || (key == '!'))) {
      delay(300);
      score++;
    }
  }
  if (screen ==10) {
    background(#0C550F);
    textSize(30);
    text("Question 9:", 25, 100);
    text("Alexander Graham Bell inveted the light bulb.", 25, 160);
    fill(#1BBF48);
    rect(0, 650, 750, 250);
    fill(#ED182A);
    rect(660, 650, 750, 250);
    fill(0);
    textSize(100);
    text("T)", 50, 800);
    text("True", 160, 800);
    text("F)", 720, 800);
    text("False", 830, 800);
    //image(light, 500, 200);
    textSize(60);
    text("/12", 1145, 100);
    textSize(60);
    text(score, 1100, 100);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == 't') || (key == 'T'))) {
      delay(300);
      score++;
    }
  }

  if (screen ==11) {
    background(#34B6CE);
    text("Question 9:", 25, 100);
    text("Where is Mount Everest located?.", 25, 160);
    fill(#FCBB52);
    rect(0, 640, 660, 160);
    rect(660, 640, 700, 160);
    rect(0, 800, 660, 160);
    rect(660, 800, 700, 160);
    fill(0);
    text("1)", 40, 715);//Questions
    text("2)", 700, 715);
    text("3)", 40, 865);
    text("4)", 700, 865);
    text("Tibet", 120, 715);
    text("Nepal", 780, 715);
    textSize(30);
    text("Border betweeem Tibet and Nepal", 120, 865);
    text("China", 780, 865);
    fill(0);
    textSize(60);
    text("/12", 1165, 100);
    textSize(60);
    text(score, 1100, 100);
    scale(0.3);
    //image(mount, 600, 600);
    //asnwer to previous question adds score if code is in next screen
    if ((keyPressed == true) && ((key == 'f') || (key == 'F'))) {
      delay(300);
      score++;
    }
  } else if (screen ==12) {
    background(#FFA600);
    fill(0);
    textSize(60);
    text("/12", 1165, 100);
    textSize(60);
    text(score, 1100, 100);
    textSize(40);
    text("Question 11:", 25, 100);    
    text("Mitochandrian is the \"_ _ _ _ _ _ _ _ _ _\"  of the cell", 25, 160);
    fill(255, 255, 0);
    text(s, 240, 120);
  } else if (screen == 13) {
    background(0);
    fill(255);
    text("powerhouse is correct", 130, 130);
  } else if (screen == 14) {
    background(0);
    fill(255);
    text("WRONG! \n\n powerhouse is correct", 130, 130);
  } else if (screen == 15) {
    background(0);
    fill(255);
    text("Quiz is over! \n\n           ", 130, 130);
  }

  //answer to previous question adds score if code is in next screen
  if ((keyPressed) && ((key == '3') || (key == '#'))) {
    delay(300);
    score++;
  }
}

void keyPressed() {
  // ---------------------------------------
  if (screen==12) {

    if (key>='a'&&key<='z') {
      s+=key;
    }
    if (key==ENTER||key==RETURN) {
      if (s.equals("powerhouse")) {
        screen = 13;
      } else {
        screen = 14;
      }
      s="";
    }
  }
  // ---------------------------------------
  else if (screen==13 || screen==14) {
    screen=15;
  }

  // ---------------------------------------
  else if (screen==15) {
    screen=0;
  }
  // ---------------------------------------
  else {

    if (keyPressed && screen >=0 ) {
      screen = screen + 1;
    }
  }
}
2 Likes

you should also check for allowed letters when answering:

sometimes 1,2,3,4

sometimes t, f, T, F

at the moment, user can press any key :wink:

1 Like

Chrisir, thank you , I owe you so much!! this works super well with my code and I can manipulate it as I wish, again thank you so much :smile: :orange_heart:

1 Like