Why is it i need transistors and resistors to turn a dc motor with an Arduino but i can connect it directly to a battery
If you want the motor to rotate continuously, without using PWM, and without switching the motor on and off from the Arduino, you can connect the motor straight to 5V and ground. If you then add a large resistor like you tried, not enough current will pass through the motor to rotate it; in the image the resistor is there to limit the current into the transistor, not to limit the current into the motor.
You can't connect a motor directly to an IO pin because an IO pin can only deliver about 20mA, which isn't enough for a motor. So, if you want to control a motor from an IO pin, you need a transistor as a switch and you operate that transistor from the IO pin. The transistor does the heavy lifting and switches the larger current the motor needs. The resistor is there to limit the current into the transistor.
Note that it is generally better to wire a motor directly to a 5V power source and not to the 5V pin on the Arduino, as the current you can get from that pin is limited; it will do for small motors, though, if they don't pull more than, let's be safe, about 300mA. In other words, it is preferred not to use the Arduino 5V pin as a power source, but use a 5V power source directly.
Also note that you always need the diode across the motor, however you wire it. It keeps inductive spikes away from the rest of your circuit.