 Hey guys, right now I'm going to be going over the functions lab one tutorial workshop And I'm going to be doing question one So we can see from the question that we're given a follow or a function called triple and it returns to us Whatever our input is multiplied by three. So we've got our return type here is an integer We've got the name of the function is triple. We have our input is And it's this variable n which is an integer And then it's going to return n times three So let's just look at the first part of it and anything we do here we can always test with Processing which is great, but just make sure when you do it you have void setup I know some people are having issues with mixing active and static mode And that's because you were trying to write this function, but you didn't have void set up So if you have functions and you need to include this void setup, so you don't get that error but first let's just take a look at this triple one and See what's going to happen with it and if it's even valid So first we're calling triple and then we come into triple and we give triple the input of one and Triple requires that it has one input and it requires that that one input is an integer So this works out because we're giving it one which is an integer So and it's going to return to us It's it it will replace this n with one and then it will return to us one times three which will be three So we should get three down here Which we do So for 1.2, I'll just copy and paste what the problem is into here So we've got this integer m which is two We've got an integer p which is calling triple m and then we want to print p So we can come up here to where the calling of the function is and it's It's going to input the variable m So m is two which is an integer and we if we come down here We know that triple needs an integer so this is valid so we can call triple with our variable m 2 So now m is going to be put into here So it'll become 2 and then 2 becomes the variable n So n is a local variable for 4 triple So now instead of the variable being m. It's replaced and now n is our variable that we're looking at So now we're going to get 2 times 3 Which will be 6 so now p is going to be equal to 6 and this works out as well because P is an integer and an integer is returned to us So now when we print p we should get 6 Which we do so let's look at this next one so we're gonna call the function triple with 3 and 4 and We can already see here that this is invalid The reason for this is because triple only takes one input and we're trying to give triple two inputs So we're saying here triple here are these two inputs and triples complaining because it's saying you only told me what to do with one input I don't know what else to do So it's complaining to us. So this is invalid. This this won't run All right, so on to 1.4 We've got an integer m which is equal to 3 and Then we want to Print triple m plus 2 So when we call triple We're saying m which is 3 plus 2 which is 5. So when we call triple N is going to be equal to 5 because that's m plus 2 or 3 plus 2 and Then we enter in with n being equal to 5 And then we do 5 times 3 which is 15 and our output should be printed our effect should be 15 And we can see down here that that's correct So now on to 1.5 We have a variable fill red and it's a boolean and We're calling triple five for it So this is invalid. We're gonna get an error for this the reason for this is because We can call triple five as we know before this works. We can call triple five. It's gonna Put five in is n Five times three is 15 and then it'll return the integer 15 to us But the issue is that we're trying to put an integer Into a boolean so fill red is supposed to be a boolean value and we're trying to insert an integer which doesn't work out This isn't consistent. So we're gonna get a complaint from processing. So this is invalid And then we've got this for our last 1.6 we've got this nested Function call Which I know seems a bit confusing Let's just try and work out down here what's gonna happen So we've got this the first thing that we want to do is hop into the middle Because as we know from the basics of math operators, we need to go into the parentheses first So first we'll do This triple I call so we know that I is gonna be equal to one I mean if you're ever confused with any of this sometimes I like to write it down on a piece of paper and basically do this process Which is just going through it myself and trying to figure out what the values are gonna be if you're ever confused with anything So we know that I is gonna be one so we can replace I with one and then when we call triple one And we'll now be equal to one one times three is three. So three is gonna be returned to us So we know that triple one is gonna equal three and then we can do this whole parentheses So we know J is now equal to two Three plus two is five and as we know from our previous questions Triple five is gonna give back 15 to us So the value 15 should be printed so when we run this We can see that down here And another good thing to do if you're ever maybe a bit confused about what's happening is to use the debugger And I will show you with we'll go back to one point two because that's a good example to show the debugger with We can come up here and we can put breakpoints on everything that's happening And then we can run this it'll first stop it and it's equal to two So we'll step through this so we can see here our variable m and then We have our triple m which we know will be equal to six then we have this integer p So we step through that Now we jump we jump into the function because we called triple m So now that shows our variable n which is now two so m was two and then we put m into our Into our call for triple and then triple replaces n with two So now we also have this local variable n which is two so we can see that here Because these two variables are local to set up and this variable is this variable n is local to triple So now we don't see these variables anymore, and we just see the variable n, but then if we step out of this And is no longer here because we're back into the setup So after we call triple it comes back up to set up and this The the variable n isn't local for setup variable n is local for triple So we don't have any or we don't see n anymore So now we come up to here, and we go back up, and we see n again because we're back into the setup function Step through this we now get our variable p is shown Which we know is six and then it steps through and we get our output So if you're ever confused with how something's working with a function again I suggest writing it down and kind of trying to work through it yourself or using the Debugger and stepping through Each line of code to see what local variables and what global variables we have And kind of what's going on So hopefully this helped for you guys