In this project, we will create a program consisting of multiple functions to represent a car driving.
With functions, we can combine them to perform, well, really anything! Let's create a function to create a new car:
func new_car() {
give "Jeep Grand Cherokee"; # use 'give' to return values from a function
}
Since this function gives us a new car as a string, let's add a way to make the car drive!
func start_driving(car) {
bark("Car '" + car + "' is driving");
}
Also make sure to add the stop function:
func stop_driving(car) {
bark("Car '" + car + "' has been stopped");
}
Now, we can combine it all together and call all the appropriate functions:
obj my_car = new_car();
start_driving(my_car);
stop_driving(my_car);
The final code should look something similar to this:
func new_car() {
give "Jeep Grand Cherokee";
}
func start_driving(car) {
bark("Car '" + car + "' is driving");
}
func stop_driving(car) {
bark("Car '" + car + "' has been stopped");
}
obj my_car = new_car();
start_driving(my_car);
stop_driving(my_car);