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.

The makeSandwich() function is provided in main.js. It is defined with two parameters, topping1 and 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 'bread'.

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 result.

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 'burger patty' and 'pickles' to 'peanut butter' and 'jelly', then
  • Run the code

Congrats, you’re coding with JavaScript! Feel free to try other toppings you’ve seen throughout this lesson.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?