Welcome back.
We learned about functions.
Now let's solve this practice.
Build a simple calculator function that does the and and calculates the arithmetic operations subtraction,
addition, multiplication and division and make it functional and can be used okay.
So for that we need to define functions I want from you to pause the video and think about it.
Create four functions and let's try to solve it.
I hope you pause the video, think about it and solve it correctly.
Otherwise don't worry, we're going to clarify everything.
At first we can define a new function called add takes into parameters two, a and b.
We can define a return statement a plus b.
This is very simple.
Another function called subtract a minus b, return a minus b another function.
Multiply a times b and divide a over b.
But here there is a very important note b will should not be Zero.
So if we need to use if B doesn't equal to zero, return A over B.
Otherwise can't divide by zero.
So here inside this function test, if B is not zero.
If it is zero, go and tell the compiler to return can divide by zero message.
Otherwise, if b is not equal to zero, return a over B and do the division function.
Let's test our code.
So here testing our calculator.
Define two variables x equal to ten y equals to 8 or 20.
Let's test the addition.
Print any errors.
Run.
And here we go.
Ten plus 20 equals to 30.
Let's test the subtract multiply and divide.
Let's run.
And here we go ten -20 -1010 times 2210 over 20 0.5 okay congratulations guys.
We succeeded in building this simple calculator using functions and the return statement.