Reaction time experiment

thank you! I realized that. Now I’m having a problem with having the calculation of the reaction time work. It should show the time that it takes for the user to press space since the square turned red. Could you help?

boolean startTimer = false;
int startingTimer;
int CONSTANT = 1000;
int r;
int timeOne;
int timeTwo;
int totalTime;
int reactionTime;
boolean reaction;

void setup() {   // setting up the initial screen
  size(800, 800);
  textSize(36);
  text("Reaction time experiment", 180, 200);
  textSize(32);
  text("Press SPACE to start", 250, 400);
}

void keyPressed() {
  if (key == ' ') {
    startTimer=true;
    startingTimer = millis();

    r = int(random(2000, 6000)); // selects random timestamp
  }
}

void reaction() {
  reactionTime = millis() - totalTime;
}

void draw() {

  if (startTimer==true) { // dictates what happens after space is pressed
    background(255);

    totalTime = (int(millis()) - startingTimer); // subtracts the time spent from pressing space from the real time
    fill(0, 0, 0);
    rectMode(CENTER);
    rect(400, 400, 400, 300); // inital black rectangle
    text("reaction" + reactionTime, 400, 200);

    if (r <= totalTime) {
      reaction = true;
      //timeOne = millis() - totalTime;
      text("totalTime" + totalTime, 100, 100);
      //text("timeOne" + timeOne, 200, 200);
      //text("timeTwo" + timeTwo, 200, 200);
      fill(255, 0, 0);
      rect(400, 400, 400, 300);
      fill(0, 0, 0);
      if (keyPressed == true) {
        if (key == ' ') {
          //timeTwo = millis() - totalTime;
          reaction = false;
        }
      }
    }
  }
}