Difference between revisions of "PHP-and-MySQL/C2/Functions-Advanced/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with '{| border=1 !Time !Narration |- |0:02 |Welcome to the Spoken Tutorial on Advanced Function. Here, I'll show you how to create a little calculator program. |- |0:11 |We will deal …')
 
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{| border=1
 
{| border=1
!Time
+
|'''Time'''
!Narration
+
|'''Narration'''
 
|-
 
|-
|0:02
+
|00:03
|Welcome to the Spoken Tutorial on Advanced Function. Here, I'll show you how to create a little calculator program.
+
|Welcome to the Spoken Tutorial on '''Advanced Functions'''. Here, I'll show you how to create a little calculator program.
 
|-
 
|-
|0:11
+
|00:11
|We will deal with a function that allows you to input a value.  Then gain a value out of this, after a mathematical operation
+
|We will deal with a '''function''' that allows you to '''input''' a value, then gain a value out of this after a mathematical operation.
 
|-
 
|-
|0:19
+
|00:20
|So, we'll create a function in the same way that we've done before. I'll call this 'calc'
+
|So, we'll create a function in the same way that we've done before. I'll call this 'calc'.
 
|-
 
|-
|0:26
+
|00:27
|And I'm going to create my first block . Here , I'll type 'number1', 'number2' and an 'operator'
+
|And I'm going to create my first '''block''' . Here, I'll type 'number1', 'number2' and an 'operator'.
 
|-
 
|-
|0:35
+
|00:35
|Now this will be a numerical value. This will be an integer or decimal, depending on the user-input. This will also be the same and this will be the string value of either 'add' 'subtract' 'multiply' or 'divide'
+
|Now this will be a numerical value. This will be an integer or decimal, depending on the user-input. This will also be the same and this will be the '''string''' value of either 'add' 'subtract' 'multiply' or 'divide'.
 
|-
 
|-
|0:52
+
|00:52
|Now inside our function we need to start creating our code. I'm going to create a switch statement inside.
+
|Now, inside our '''function''' we need to start creating our '''code'''. I'm going to create a '''switch''' statement inside.
 
|-
 
|-
 
|01:00
 
|01:00
|I'll say switch and put the switch condition or rather the input of the switch is 'op'
+
|I'll say '''switch''' and put the '''switch condition''' or rather the input of the switch is '''$op'''.
 
|-
 
|-
|1:08
+
|01:09
|I'll create a block for this and I'll say case = plus then carry out this.
+
|I'll create a '''block''' for this and I'll say '''case''' "+" (plus) then carry out this.
 
|-
 
|-
|1:18
+
|01:18
|I'll make a new variable called 'total' which will be equal to 'num1' which is input here plus 'num2'
+
|I'll make a new variable called '''$total''' which will be equal to 'num1' which is input here plus 'num2'.
 
|-
 
|-
|1:31
+
|01:32
|I'll break that with a semicolon.  Now there's probability a much easier way to do this by combining the switch statement with a function.  
+
|I'll '''break''' that with a semicolon.  Now there's a probability, a much easier way to do this by combining the '''switch''' statement with a function.  
 
|-
 
|-
|1:43
+
|01:44
|So you will be able to use all different kinds of things inside other statements and inside functions.
+
|So, you will be able to use all different kinds of things inside other statements and inside functions.
 
|-
 
|-
|1:51
+
|01:52
|So I have created a case for 'plus'. So when this equals to 'plus' supplied by the user, we have 'num1' added to 'num2'.
+
|So I have created a '''case''' for 'plus'. So when this equals to 'plus' supplied by the user, we have '$num1' added to '$num2'.
 
|-
 
|-
|2:03
+
|02:03
|Now we need to go down and create another 'case', which is 'minus'. I'll type total = 'num1' - 'num2'
+
|Now we need to go down and create another '''case''' which is 'minus'. I'll type '''$total = $num1 - $num2;'''
 
|-
 
|-
|2:17
+
|02:17
| We will scroll down. Make sure you break that.  
+
| We will scroll down; make sure you break that.  
 
|-
 
|-
|2:20
+
|02:21
 
|We'll now copy this code down.  
 
|We'll now copy this code down.  
 
|-
 
|-
|2:23
+
|02:24
|And here we'll say 'multiply' and we'll say 'divide' and make sure you change the sign here.
+
|And here, we'll say "*" (multiply) and we'll say "/" (divide) and make sure you change the sign here.
 
|-
 
|-
|2:34
+
|02:34
 
|Now if you don't understand what is going on please feel free to contact us via e-mail. I hope every confusion will be resolved in that way.
 
|Now if you don't understand what is going on please feel free to contact us via e-mail. I hope every confusion will be resolved in that way.
 
|-
 
|-
|2:45
+
|02:45
|In the default we're going to echo out 'unknown operator'. OK?
+
|In the default, we're going to '''echo''' out "Unknown operator". OK?
 
|-
 
|-
|2:51
+
|02:51
|Let me just run through this. Then we will start to call the function.  
+
|Let me just run through this. Then we will start to '''call''' the '''function'''.  
 
|-
 
|-
|2:56
+
|02:56
|I have got a function called calculator or calc for short, which takes a number as input, then a second number and then an operator which could be either 'plus' 'minus' 'multiply' or 'divide'.
+
|I have got a function called calculator or '''calc''' for short which takes a number as input, then a second number and then an operator which could be either 'plus' 'minus' 'multiply' or 'divide'.
 
|-
 
|-
|3:12
+
|03:12
| As you have probably seen in my mathematical operator - sorry in my arithmetic operator tutorial.
+
| As you have probably seen in my mathematical operator - sorry in my '''Arithmetic Operator''' tutorial.
 
|-
 
|-
|3:20
+
|03:20
|Now we have a switch statement inside, which takes this 'op' into account. It takes what has been entered. Now if it equals to a 'plus', remember that it switches over to this statement. It is easier to write and much more efficient.
+
|Now we have a '''switch''' statement inside which takes this '''$op''' into account. It takes what has been entered. Now if it equals to a 'plus'(+), remember that it switches over to this statement. It is easier to write and much more efficient.
 
|-
 
|-
|3:42
+
|03:42
|If it equals to a 'plus' then we will create a new variable called 'total'.  
+
|If it equals to a "+" (plus) then we will create a new variable called 'total'.  
 
|-
 
|-
|3:48
+
|03:48
 
|That's going to be equal to the first number which was entered and added to the second number which was entered.
 
|That's going to be equal to the first number which was entered and added to the second number which was entered.
 
|-
 
|-
|3:56
+
|03:56
|Here we will say if it's a 'minus', then the variable 'total' - okay remember, the variable 'total' will only be set once for each case either plus or minus - so this total variable going to be number 1 - number 2 and the same for multiply and divide as well.
+
|Here, we will say if it's a "-" (minus) then the variable 'total' - okay remember, the variable 'total' will only be set once for each '''case''' either plus or minusso this '''$total''' variable going to be number1 - number2 and the same for multiply and divide as well.
 
|-
 
|-
|4:21
+
|04:21
|Now this would do absolutely nothing. Refresh this. Now, if we enter this page, there is nothing, because we haven't called our function.  
+
|Now this would do absolutely nothing. '''Refresh''' this. Now, if we enter this page, there is nothing because we haven't called our '''function'''.  
 
|-
 
|-
|4:32
+
|04:33
|Now to call our function, as you know, we will just say calc and put our values in.
+
|Now to call our '''function''', as you know, we will just say '''calc();''' and put our values in.
 
|-
 
|-
|4:40
+
|04:40
|Let's us just give it two numbers say 10 and 10 and a 'plus' . Okay, so that will be 20. Now watch what happens if I refresh this. Nothing. Now why?
+
|Let us just give it two numbers say 10 and 10 and a "+" (plus). Okay, so that will be 20. Now watch what happens if I '''refresh''' this. Nothing. Now why?
 
|-
 
|-
|4:55
+
|04:55
 
|The reason is that we haven't echoed this out. We've just set it as a variable.  
 
|The reason is that we haven't echoed this out. We've just set it as a variable.  
 
|-
 
|-
|5:01
+
|05:01
|So what we would ideally do is we will echo what has been out put from calc. Now, at the moment this won't do anything if we do a refresh
+
|So, what we ideally do is, we will echo what has been '''output''' from '''calc'''. Now, at the moment this won't do anything if we do a '''refresh'''.
 
|-
 
|-
|5:11
+
|05:11
|We have got nothing, because, there is no return output. So, in each case what we should say is 'return total'.  
+
|We have got nothing because there is no return output. So, in each case, we should say '''return''' '''$total;'''.  
 
|-
 
|-
|5:23
+
|05:24
|What this does is - If you think of the function as a variable it sets the function's value as the total.
+
|What this does is - if you think of the function as a variable, it sets the function's value as the '''$total'''.
 
|-
 
|-
|5:32
+
|05:32
|As long as you say return whatever you say here the function will equal that.  
+
|As long as you say '''return''', whatever you say here, the function will equal that.  
 
|-
 
|-
|5:39
+
|05:39
|So we are going to say return total and we are going to copy that and paste it down for each case.  
+
|So, we are going to say '''return $total''' and we are going to copy that and paste it down for each '''case'''.  
 
|-
 
|-
|5:47
+
|05:47
|Okay so obviously we don't need to do that for unknown operator. This is because, there is no operator to be found here.
+
|Okay. So, obviously we don't need to do that for "Unknown operator". This is because there is no operator to be found here.
 
|-
 
|-
|5:57
+
|05:58
|And we can refresh that.
+
|And we can '''refresh''' that.
 
|-
 
|-
|6:00
+
|06:00
 
|We still don't have anything. Guess why?
 
|We still don't have anything. Guess why?
 
|-
 
|-
|6:04
+
|06:04
 
|The reason this is not working is because I've echoed this inside a function. That's a mistake.
 
|The reason this is not working is because I've echoed this inside a function. That's a mistake.
 
|-
 
|-
|6:10
+
|06:10
|You can see the bracket of a function that starts here and ends here
+
|You can see the bracket of a function that starts here and ends here.
 
|-
 
|-
|6:14
+
|06:15
|I'll place this underneath here, where it should be and then refresh it. It's 20 okay, we can see the 10 + 10 is 20 through our function
+
|I'll place this underneath here where it should be and then '''refresh''' it. It's 20. okay, we can see the 10 + 10 is 20 through our function.
 
|-
 
|-
|6:37
+
|06:37
 
|So let's pick some different values, say, 13 and 7 and divide. Let's see what we get.  
 
|So let's pick some different values, say, 13 and 7 and divide. Let's see what we get.  
 
|-
 
|-
|6:46
+
|06:46
|Okay, we have got a quiet long decimal number. So you can see that this is quite good function that we have made. We have got our first number, our second number and an operator.
+
|Okay, we have got a quite long decimal number. So you can see that this is quite good function that we have made. We have got our first number, our second number and an operator.
 
|-
 
|-
|6:59
+
|07:00
|And through a switch statement it detects which one and performs the relevant operation to it.  
+
|And through a '''switch''' statement, it detects which one and performs the relevant operation to it.  
 
|-
 
|-
|7:06
+
|07:06
|An unknown operator error will be given if it can't be determined.
+
|An "Unknown operator" error will be given if it can't be determined.
 
|-
 
|-
|7:11
+
|07:11
|So, for example let's take 'a' which is not a valid operator. As soon as we refresh it's going to unknown operator. This brings us to the end of the tutorial on advanced functions. We saw that we can input a value and then returned a value echoing out using a return command.
+
|So, for example let's take "a" which is not a valid operator. As soon as we refresh, it's going to unknown operator. This brings us to the end of the tutorial on '''Advanced Functions'''. We saw that we can '''input''' a value and then returned a value echoing out using a '''return''' command.
 
|-
 
|-
|7:31
+
|07:31
|This is Sidharth dubbing for the Spoken Tutorial Project. Thanks for watching.
+
|This is Sidharth, dubbing for the Spoken Tutorial Project. Thanks for watching.
 
|-
 
|-

Latest revision as of 22:39, 25 May 2015

Time Narration
00:03 Welcome to the Spoken Tutorial on Advanced Functions. Here, I'll show you how to create a little calculator program.
00:11 We will deal with a function that allows you to input a value, then gain a value out of this after a mathematical operation.
00:20 So, we'll create a function in the same way that we've done before. I'll call this 'calc'.
00:27 And I'm going to create my first block . Here, I'll type 'number1', 'number2' and an 'operator'.
00:35 Now this will be a numerical value. This will be an integer or decimal, depending on the user-input. This will also be the same and this will be the string value of either 'add' 'subtract' 'multiply' or 'divide'.
00:52 Now, inside our function we need to start creating our code. I'm going to create a switch statement inside.
01:00 I'll say switch and put the switch condition or rather the input of the switch is $op.
01:09 I'll create a block for this and I'll say case "+" (plus) then carry out this.
01:18 I'll make a new variable called $total which will be equal to 'num1' which is input here plus 'num2'.
01:32 I'll break that with a semicolon. Now there's a probability, a much easier way to do this by combining the switch statement with a function.
01:44 So, you will be able to use all different kinds of things inside other statements and inside functions.
01:52 So I have created a case for 'plus'. So when this equals to 'plus' supplied by the user, we have '$num1' added to '$num2'.
02:03 Now we need to go down and create another case which is 'minus'. I'll type $total = $num1 - $num2;
02:17 We will scroll down; make sure you break that.
02:21 We'll now copy this code down.
02:24 And here, we'll say "*" (multiply) and we'll say "/" (divide) and make sure you change the sign here.
02:34 Now if you don't understand what is going on please feel free to contact us via e-mail. I hope every confusion will be resolved in that way.
02:45 In the default, we're going to echo out "Unknown operator". OK?
02:51 Let me just run through this. Then we will start to call the function.
02:56 I have got a function called calculator or calc for short which takes a number as input, then a second number and then an operator which could be either 'plus' 'minus' 'multiply' or 'divide'.
03:12 As you have probably seen in my mathematical operator - sorry in my Arithmetic Operator tutorial.
03:20 Now we have a switch statement inside which takes this $op into account. It takes what has been entered. Now if it equals to a 'plus'(+), remember that it switches over to this statement. It is easier to write and much more efficient.
03:42 If it equals to a "+" (plus) then we will create a new variable called 'total'.
03:48 That's going to be equal to the first number which was entered and added to the second number which was entered.
03:56 Here, we will say if it's a "-" (minus) then the variable 'total' - okay remember, the variable 'total' will only be set once for each case either plus or minus, so this $total variable going to be number1 - number2 and the same for multiply and divide as well.
04:21 Now this would do absolutely nothing. Refresh this. Now, if we enter this page, there is nothing because we haven't called our function.
04:33 Now to call our function, as you know, we will just say calc(); and put our values in.
04:40 Let us just give it two numbers say 10 and 10 and a "+" (plus). Okay, so that will be 20. Now watch what happens if I refresh this. Nothing. Now why?
04:55 The reason is that we haven't echoed this out. We've just set it as a variable.
05:01 So, what we ideally do is, we will echo what has been output from calc. Now, at the moment this won't do anything if we do a refresh.
05:11 We have got nothing because there is no return output. So, in each case, we should say return $total;.
05:24 What this does is - if you think of the function as a variable, it sets the function's value as the $total.
05:32 As long as you say return, whatever you say here, the function will equal that.
05:39 So, we are going to say return $total and we are going to copy that and paste it down for each case.
05:47 Okay. So, obviously we don't need to do that for "Unknown operator". This is because there is no operator to be found here.
05:58 And we can refresh that.
06:00 We still don't have anything. Guess why?
06:04 The reason this is not working is because I've echoed this inside a function. That's a mistake.
06:10 You can see the bracket of a function that starts here and ends here.
06:15 I'll place this underneath here where it should be and then refresh it. It's 20. okay, we can see the 10 + 10 is 20 through our function.
06:37 So let's pick some different values, say, 13 and 7 and divide. Let's see what we get.
06:46 Okay, we have got a quite long decimal number. So you can see that this is quite good function that we have made. We have got our first number, our second number and an operator.
07:00 And through a switch statement, it detects which one and performs the relevant operation to it.
07:06 An "Unknown operator" error will be given if it can't be determined.
07:11 So, for example let's take "a" which is not a valid operator. As soon as we refresh, it's going to unknown operator. This brings us to the end of the tutorial on Advanced Functions. We saw that we can input a value and then returned a value echoing out using a return command.
07:31 This is Sidharth, dubbing for the Spoken Tutorial Project. Thanks for watching.

Contributors and Content Editors

Minal, Pratik kamble, Sandhya.np14, Sneha