17.5. Creating a Procedure with Parameters¶
Is there another way to make it easy to change the story, rather than creating a string and then splitting it into pieces? We can create a procedure with parameters and then pass in the input values when we call the procedure as shown below.
Creating a procedure with parameters makes it easy to customize the madlib stories without having to split a string. The split
function is very useful when you read data from a file or from a website.
- Emily
- That is the value of firstName.
- Smith
- That is the value of lastName.
- girl
- That is the value of gender.
- 2783 Main Street
- That is the value of address.
- smell
- That is the value of verb.
What would be the value of lastName
in witchStory
given the following call to the procedure?
witchStory("Emily", "Smith", "girl", "2783 Main Street", "smell")
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.