WEBVTT

00:00.080 --> 00:00.920
Welcome back.

00:00.960 --> 00:02.640
We learned about functions.

00:02.640 --> 00:04.800
Now let's solve this practice.

00:04.840 --> 00:16.440
Build a simple calculator function that does the and and calculates the arithmetic operations subtraction,

00:16.480 --> 00:22.800
addition, multiplication and division and make it functional and can be used okay.

00:22.960 --> 00:29.640
So for that we need to define functions I want from you to pause the video and think about it.

00:29.840 --> 00:34.760
Create four functions and let's try to solve it.

00:34.760 --> 00:39.880
I hope you pause the video, think about it and solve it correctly.

00:40.000 --> 00:43.520
Otherwise don't worry, we're going to clarify everything.

00:43.800 --> 00:52.560
At first we can define a new function called add takes into parameters two, a and b.

00:52.800 --> 00:58.200
We can define a return statement a plus b.

00:58.320 --> 00:59.640
This is very simple.

00:59.800 --> 01:09.520
Another function called subtract a minus b, return a minus b another function.

01:09.560 --> 01:15.720
Multiply a times b and divide a over b.

01:15.840 --> 01:23.000
But here there is a very important note b will should not be Zero.

01:23.160 --> 01:31.680
So if we need to use if B doesn't equal to zero, return A over B.

01:31.720 --> 01:35.640
Otherwise can't divide by zero.

01:35.720 --> 01:41.200
So here inside this function test, if B is not zero.

01:41.360 --> 01:49.760
If it is zero, go and tell the compiler to return can divide by zero message.

01:50.000 --> 01:58.480
Otherwise, if b is not equal to zero, return a over B and do the division function.

01:58.520 --> 02:00.280
Let's test our code.

02:00.280 --> 02:03.720
So here testing our calculator.

02:03.760 --> 02:11.200
Define two variables x equal to ten y equals to 8 or 20.

02:11.360 --> 02:13.240
Let's test the addition.

02:13.240 --> 02:14.720
Print any errors.

02:14.880 --> 02:15.560
Run.

02:15.560 --> 02:16.560
And here we go.

02:16.600 --> 02:20.040
Ten plus 20 equals to 30.

02:20.080 --> 02:25.200
Let's test the subtract multiply and divide.

02:25.200 --> 02:26.080
Let's run.

02:26.080 --> 02:38.480
And here we go ten -20 -1010 times 2210 over 20 0.5 okay congratulations guys.

02:38.640 --> 02:45.760
We succeeded in building this simple calculator using functions and the return statement.
