VOCABULARY
Parameter - The parameters of a function are the items/values/conditions that you can input into a function to be processed. In many cases, the parameter may be a specific characteristic or condition, or value that you want the function to evaluate. The parameter is a definition or placeholder of a function. The parameter is NOT a value, it is a placeholder for a value that will be inputted.
Argument - An argument is a value that is imputed into the procedure/function when it is called, a certian amount of arguments are added to satisfy the amount and type of parameters. The argument is usually an integer or string.
In the makeCake function example, our parameters would be makeCake(layers,flavor) meaning the parameters/conditions we want to know are how many layers and what flavor the cake will have. The argument when we run the function makeCake(3,"lemon") would be 3 as the layers and "lemon" as the flavor, as those were the values the user inputted to satisfy the parameters.
Return - The return command is a command used to exit a function and output any specific values the user wants
In this example, the function takes a random compliment and creates a statement with the comment and the name. Then, the statement is returned back to be stored or outputted. Once statement is returned, the function terminates.
Library - A library is a collection of pre-written functions or procedures that a programmer can input into their own programs to use. A library is very useful as it makes it so that you don't have to write your own functions for tasks that have already been written.
API - API stands for Application Programming Interface, which is a set of rules, protocols, and tools for construction a software application. In libraries, the API will tell the user the inputs and outputs of a specific function or procedure as well as their specific purpose and how they should interact
In this example, the library, LibraryPractice (while not the best name), is a library composed of three functions, isEven, isOdd, and isBetween. This means if I have a program for example that takes a number, finds if it is even or odd, and checks if it is in between 5 and 20, instead of having to write to code for even-odd and in between, instead, I can use the built in functions in the library to simplify the process and write less code.
In the LibraryPractice library (other than the name), each of the functions are given a specific name, as well as commenting around it to tell the user what and how the function works. For example, in the isEven function, it states that the purp[ose is to decide if a number is even. Then, it tells the user the parameters and returns of the function, in this case, the parameter is an integer, which is the number you are trying to determine if it is even, and the return value is a boolean (true or false) which states if the number is even or not. This is the API of the LibraryPractice function.
Written Response
The purpose of the decideWinner function is to take two string parameters, the playerChoice and the computerChoice, and return a string of what it calculates the outcome of the game to be. The program has three main tasks, first getting a user input and randomly generating a computer input, then comparing the two and finding out the outcome of the match, and then displaying the information and recording the score. The decideWinner function contributes to the program by allowing us to solve the second task, meaning after we have obtained a computer and player choice, we can process them through the decideWinner function to find a result to record and display.
The decideWinner function uses a chain of if and else if statements to check all possible configurations that the computer and player could be in. First, we create a winner variable that we will use to store the final result and return back to the program. Then we starting writing if/else if statements for each of the cases written in a format like this: if/else if (playerChoice == "(Rock, Paper or Scissors)" && (and) computerChoice == "(Rock, Paper or Scissors)") { winner = "Outcome of the pair" }. We keep on doing this until we have checked all possibilities, and finally at the end we return the winner (Computer, Player, or Draw) back to the user.