Codecademy Forums

FAQ: Functions - Putting It All Together

// Define the ‘makeSandwich()’ function
function makeSandwich(topping1, topping2, topping3) {
sandwich = ‘bread’ + ‘,’
sandwich += topping1 + ‘,’
sandwich += topping2 + ‘,’
sandwich += topping3 + ‘,’
sandwich += ‘bread’
return sandwich
}

// Call the function and store the returned value in ‘result’
result = makeSandwich(‘jelly’, ‘cheese’, ‘ham’)

I can’t solve the problem, what I did wrong ?

It could be just a matter of missing white space after the comma so the toppings are separated as in a sentence.

Hi, I’m having the same problems as kellebelle99,

https://www.codecademy.com/paths/code-foundations/tracks/learn-how-to-code/modules/bop-ii/lessons/bop-functions/exercises/all-together

I tried to running the function that was already set up, but that doesn’t make the burger sandwich so I don’t know where I messed up.

Could someone explain mtf in a different way?

Hello, @dog_geist! Welcome to the forum.
If you wouldn’t mind copying and pasting the code you are having trouble with in a reply to this post we’ll be happy to try to help. Please click on the </> icon before pasting your code, and then paste it in the space indicated. Without seeing the code in question, it is really difficult to speculate what may be wrong.

Hi, thanks for responding, but interestingly enough it works now.

// Define the 'makeSandwich()' function
function makeSandwich(topping1, topping2) {
  sandwich = 'bread' + ','
  sandwich += topping1 + ','
  sandwich += topping2 + ','
  sandwich += 'bread'
  return sandwich
}

// Call the function and store the returned value in 'result'
result = makeSandwich('peanut butter', 'jelly')

It’s very odd, because I did nothing different. At first it wouldn’t even run the default example.

1 Like

I guess we chalk it up as a glitch. Happy coding!

1 Like

Hi midlinder,

I have the same problem as dog_geist. My code is the same as his, but it doesn’t run. I get an error and can’t move on.

Can you please help me?

If your situation is anything like mine, just wait a couple of hours and get back to it.

What is the error? Are you sure your code is exactly the same? If you could post your code, I’d be happy to try to help. It is possible that the problem is with your browser or device. You can check out this Troubleshooting Guide if you’re certain that your code is correct. The guide explains which browsers and devices work best with Codecademy, and has instructions for making sure everything is up to date.

I hope my weighing in didn’t step on any toes or anything. I just wanted to help someone out.

No worries. There have been times where a temporary glitch with the site is resolved after a few hours, so that may well have been what happened in your case. Seemed to run across just such an instance myself last night in the Python 3 course.

I think it’s just a comma, so it doesn’t read it as breadhamcheesebread, for example. Instead it reads it as bread, ham, cheese, bread. I don’t think it really matters because you’re not printing the strings anyways.