Turn the car
Let’s add method
turn to class
Run the code and we get the message
The car is turning.
We want the car to turn left sometimes and right sometimes.
When we call the
turn method we should pass which side to turn.
car1.turn("left") car1.turn("right") car1.turn("left")
turn should accept the direction of turn.
Let’s change our code.
This concept of passing different values to the same method is called passing argument.
In this case we can say that method
turn takes one argument.
In the previous lesson we saw that the method
gift also takes one argument.