LinkedIn principal author Doug Winnie explains how you can customize a function with parameters. Using parameters, a programmer can modify how a function works by changing variables within it to customize to specific situations. A function can be defined to accept one or more parameters and then refer to them throughout the code that is inside of it.
- View Offline
- When we create functions, we take actions…and group them together and give them a name.…We can then call those actions using the function name…and run them as often as we need in our code…but sometimes, we want to customize the steps a little bit…based on information we might have.…Take the example of calculating an order total.…Before we calculate a total,…there are things like sales tax and shipping cost…that might need to be added to the order…to give the total cost.…So, in our program, we have a variable…that contains the price of all the items…that are being purchased.…
We have a function that then calculates the total cost,…inside, we add a standard shipping fee…and calculate the sales tax at 8%…but sales tax rates aren't the same everywhere.…Some places have no sales tax,…some cities add to the state sales tax,…and there can be more variations.…So, we need to have a way to take the function…for calculating the total cost and modify it.…We can do this by using parameters.…It works this way.…
When we call the function that contains the code…
Join Doug Winnie as he explains the principles of programming and helps you connect to core concepts by exploring three ways that programmers perform their jobs. Doug starts by sharing the history of coding and then dives into functions, values, variables, and parameters used to define actions. He covers capturing input from users, creating conditional tests, using loops with arrays, and object-oriented programming basics. He also takes you beyond programming, into processes like debugging, refactoring, and building iteratively.
- Working with values and variables
- Breaking down tasks
- Customizing functions and parameters
- Building conditional tests
- Creating and changing arrays
- Working with objects and classes
- Debugging and refactoring code
- Going beyond the code as a programmer