Arduino motorshield is running randomly even if I gave specific command

This code is uploaded in my arduino uno with attached arduino motorshield. It doesnot works as needed . Is there a problem in the library or the arduino uno or arduino motorshield itself. It just keeps rotating.
</code?>

#include <AFMotor.h>

AF_DCMotor rightBack(1);
AF_DCMotor rightFront(2);
AF_DCMotor leftFront(3);
AF_DCMotor leftBack(4);

const int motorSpeed = 150; // Speed of the motors

void setup() {
  rightBack.setSpeed(motorSpeed);
  rightFront.setSpeed(motorSpeed);
  leftFront.setSpeed(motorSpeed);
  leftBack.setSpeed(motorSpeed);
}

void loop() {
  moveForward();
  delay(1000); // Adjust this delay as needed
}

void moveForward() {
  rightBack.run(FORWARD);
  rightFront.run(FORWARD);
  leftFront.run(FORWARD);
  leftBack.run(FORWARD);
}

Welcome to the forum

Your sketch appears to continuously call the moveForward() function with a 1 second delay between calls

What do you expect to happen when you do this ?

I just want the car to move forward but instead the dc gear motor goes backward forward randomly. I was testing the code but doesnot acts as commanded.

How many motors do you have and do they all behave the same ?

Please post a schematic of your project showing the connections between components. A 'photo of a hand drawn circuit is good enough

in which direction does run(FORWARD) turn a motor?

does the right front motor need to turn clockwise to move forward and the left front needs to turn counter-CW to move forward?

No I just need the car to run forward
only

The point being made is that in order for the car to run forward the motors on opposite sides need to run in opposite directions

Have you wired them to do that ?