Standard Arduino project

In three short words: I'm a beginner. I have a project due the day after tomorrow. I know it's supposed to be a really easy thing, but somehow I've been working on it for more than a week now and there's always some problem.
Here's the project: I have to make a car with Arduino Uno that will avoid obstacles and follow a black line.
They didn't say much about how we should assemble the car, but I googled at least a hundred times anything I had questions about and read as much as I could and watched as many videos on Youtube as I could. But somehow I still can't get it to work correctly.
Now, I'm not able to attach the photo cause it tells me the entity's too large, but I'm attaching the code I wrote for it. I know I'm asking a lot, but at this point I'm kinda desperate. I really hope someone can help me figure stuff out.

void loop() {
  
  // clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);

  // calculating the distance
  distance = duration * 0.034/2;
  Serial.print("Distance: ");
  Serial.println(distance);
  
  int valR = digitalRead(infraR);
  int valL = digitalRead(infraL);
  int valC = digitalRead(infraC);

  // if the right IR sensor detects black and other two don't
  // or if the right and the middle one detect black, turn right
  if (valL == 1 && valC == 1 && valR == 0 || valL == 1 && valC == 0 && valR == 0) {
    digitalWrite(in3, LOW);
    digitalWrite(in4, HIGH);
  }

  // if the left IR sensor detects black and other two don't
  // or if the left and the middle one detect black, turn left
  if (valL == 0 && valC == 1 && valR == 1 || valL == 0 && valC == 0 && valR == 1) {
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
  }

  // if the middle IR sensor detects black and other two don't
  // or if all three detect black, go forward
  if (valL == 1 && valC == 0 && valR == 1 || valL == 0 && valC == 0 && valR == 0) {
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    digitalWrite(in3, LOW);
    digitalWrite(in4, HIGH);
  }
  
  // car moves forward while the distance between it and an obstacle is more than 25cm
  // and goes backwards and then turns left if the distance is less than or equal to 25cm
  if (distance > 25) {
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    digitalWrite(in3, LOW);
    digitalWrite(in4, HIGH);
  }
  else {
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
    digitalWrite(in3, HIGH);
    digitalWrite(in4, LOW);
    delay(500);
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
  }
}

P.S. English isn't my first language, so if you could please tell me stuff as simply as possible I will be forever grateful. Also, ask me anything you need to know about this project. Thank you in advance.
P.P.S. the battery is 9V.

(deleted)

No photo attached. And please post the complete code. Something that will compile.

Also you need to say what components your project uses, what exactly it does now and what you expect it to do that is different.

If that 9V battery is a small rectangular smoke detector battery then it is not suitable to run motors.

Steve

Okay, sorry for all the errors. I'm using 1 Arduino uno, 1 ultrasonic sensor, 3 IR sensors, 1 h-bridge module, 2 dc motors and a breadboard. Yes, the battery is in fact small rectangular one, if not that then what should I be using? It doesn't really do anything I wrote in the code, it just goes around without purpose. I don't know how to make a diagram but I'll try making one using Tinkercad and then I'll post that too. I am trying to attach the photo, but it just tells me that the entity is too large, is there any other way I could upload it?
Here's the full code:

int in1 = 13;
int in2 = 12;
int in3 = 11;
int in4 = 10;
int echoPin = 4;
int trigPin = 5;
int infraR = 8;
int infraL = 6;
int infraC = 7;
long duration;
int distance;
int switchPin = 2;

void setup() {
  Serial.begin(9600);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(infraR, INPUT);
  pinMode(infraL, INPUT);
  pinMode(infraC, INPUT);
}

void loop() {
  
  // clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);

  // calculating the distance
  distance = duration * 0.034/2;
  Serial.print("Distance: ");
  Serial.println(distance);
  
  int valR = digitalRead(infraR);
  int valL = digitalRead(infraL);
  int valC = digitalRead(infraC);

  // if the right IR sensor detects black and other two don't
  // or if the right and the middle one detect black, turn right
  if (valL == 1 && valC == 1 && valR == 0 || valL == 1 && valC == 0 && valR == 0) {
    digitalWrite(in3, LOW);
    digitalWrite(in4, HIGH);
  }

  // if the left IR sensor detects black and other two don't
  // or if the left and the middle one detect black, turn left
  if (valL == 0 && valC == 1 && valR == 1 || valL == 0 && valC == 0 && valR == 1) {
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
  }

  // if the middle IR sensor detects black and other two don't
  // or if all three detect black, go forward
  if (valL == 1 && valC == 0 && valR == 1 || valL == 0 && valC == 0 && valR == 0) {
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    digitalWrite(in3, LOW);
    digitalWrite(in4, HIGH);
  }
  
  // car moves forward while the distance between it and an obstacle is more than 25cm
  // and goes backwards and then turns left if the distance is less than or equal to 25cm
  if (distance > 25) {
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    digitalWrite(in3, LOW);
    digitalWrite(in4, HIGH);
  }
  else {
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
    digitalWrite(in3, HIGH);
    digitalWrite(in4, LOW);
    delay(500);
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
  }
}

Elizabeth182:
It doesn't really do anything I wrote in the code, it just goes around without purpose.

You need to describe what you think it should be doing and what it actually does in as much detail as possible. We don't have your hardware so we can't try it for ourselves.

If you need to upload images see this Simple Image Guide.

A link to a short YouTube video of your car in action would also help.

This almost certainly won't do what you think because you are mixing integers and floating point maths. An Arduino is not like pocket calculator.

distance = duration * 0.034/2;

I suspect the 0.034 will be treated as 0

You need more Serial.print() statements in your program so that you can see how it is behaving.

Effective debugging starts with a testable hypothesis. What do you think might be causing the problem? What test can you do to determine if that thought is correct, or not?

...R
Planning and Implementing a Program