Time to get coding! It’s okay if you don’t recognize all the symbols in this code: we’ll walk you through the parts you need to know.
makeSandwich() function is provided in main.js. It is defined with two parameters,
topping2. By reading the instructions inside the function, we can see that it is constructing a string of words that represent the ingredients in the sandwich. For example, the first ingredient is
Below the function definition, the function is called. When called, the function outputs a string representing a custom sandwich. We say that the function returns a string. The value of that string is stored in the variable
We’ve set up the workspace so that the value of
result is translated to ingredients drawn in the app to the far right. With the below code…
result = makeSandwich('burger patty', 'pickles')
…the app will interpret
result as a bread-patty-pickles-bread sandwich and draw one to the screen.
Make a sandwich of your own by calling the function with different arguments:
- At the bottom of the code, change
- Run the code