When to use "the" before food names
Solution 1:
There are some non-standard things going on here, but for the most part this is the basic countable versus non-countable rule.
In general, if a noun refers to something that you can count, you must precede it with an article, a number, or some word indicating a quantity. If a noun refers to something that you can't count, then you don't use the article or number.
So for example, "I ate a sandwich." Sandwich is countable: you could have one sandwich, two sandwiches, etc. But "I drank milk." You don't normally talk about "one milk" or "two milks". (But we'll get back to this in a moment.) Chocolate is a general term for a substance, so you'd say, "I like chocolate." But you can make countable things out of this substance, like "I ate a chocolate bar" or "I ate a slice of chocolate cake."
But now we get to a lot of non-standard usages. People will often say, "I ordered a coffee". This is really short for "I ordered a cup of coffee", but in practice we turn the non-countable noun into a countable noun. "The waitress brought three beers" means she brought three glasses, bottles, or cans of beer, etc.
Similarly, people use "chocolate" as a countable noun to refer to small pieces of specialty chocolate candies (like Witman Samplers or your typical Valentine chocolates). So "I ate two chocolates" means "I ate two of those small pieces of chocolate candy." You would not normally use "a chocolate" to refer to a full-size candy bar, like your typical Milky Way or Mars bar or whatever. (Why? I have no idea. That's just how it is.)
"Pizza" is used as both a countable and non-countable noun. "I ate pizza" means some unspecified quantity. "I ate a pizza" means you ate an entire pizza pie. The word "pizza" is rather unusual this way.
"Noodles" is countable, but we normally eat them in fairly large quantities so we rarely really count them. No one says, "I ate 47 noodles for lunch", it's just "I ate some noodles" or "I ate noodles". But it's still a countable noun and, I think, consistently used as such. We just don't give a specific count very often.
Solution 2:
I think you must have misunderstood something. "The sandwich" and "the pizza" are both correct, but — unlike in some languages — each refers to a specific sandwich or pizza. "The pizza" means roughly "this pizza" or "that pizza". Similarly for "the sandwich", "the hamburger", "the coffee", "the chocolate", "the noodles", etc.
What you may be thinking of is a: "a sandwich" or "a hamburger" means "one sandwich" or "one hamburger" — we can't just say "I ate sandwich" or something — whereas "pizza" alone means "some amount of pizza" (not necessarily one pizza: it can be less than one pizza, or more than one).
Solution 3:
When we are talking about some types of food in general we don't use an article:
- I like pizza
- I don't drink coffee.
When we are referring to specific instances of these foods we use the definite article:
- I couldn't finish the pizza - it was too big.
- The coffee I bought at lunch tasted bitter.
But the words hamburger and sandwich are different. Unlike pizza, chocolate, coffee etc. they can only refer to specific instances of that food type. They cannot be used in the singular to refer to that type of food in general. So you cannot say:
- I like hamburger.
- I never eat sandwich.
You have to use the plural forms.