5: Return - code passes but returns 0


<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

I pass the exercise but I get a 0 subtotal when I supposed to get 22.5, and I cant seem to get why

```var orderCount =0; function takeOrder(topping, crustType){ orderCount = orderCount ++; console.log('Order: pizza with '+ " " + topping + " " +crustType); } function getSubTotal(itemCount){ return itemCount * 7.5; }

takeOrder(“bacon”, “thin”);
takeOrder(“salami”, “thick”);
takeOrder(“vegetarian”, “medium”);


orderCount isn’t defined

Sorry for a stupid question but where do I do that

You’d need to ask yourself what the code is supposed to be doing and how it should have been created. If it’s something that was described in the instructions, then you’d need to go back to that

Point is, you were using something that doesn’t exist. So either stop doing that or make it exist.

I can’t tell you what your code should be doing. That’s kind of the point with programming, you write down the actions that are to be executed. Only you know what those actions are.

But I thought I expalined what the code is supposed to to.

Make a counter, every time the counter adds an item multiply it with 7.5 and return the total wich is

3 pizzas times 7.5 i,e 22.5

Is this from a codecademy exercise? If so, then they’ll have said where to put all those things and I don’t see what you’d need me for other than not having to go back a few exercises.

If it’s not, then I imagine that you’ve got some plan for how the program should be doing these things, it sure looks like it from what code you’ve posted so far.

I just really don’t see myself being needed here. Or if I am, then I’d much rather be asking far more specific or general questions, not “how do I implement this exact behaviour” which seems like it’s meant for you to apply what you’ve learned or to do by following detailed steps already available to you

Yes it´s exersice 5: Return from the course learn javascript as the headline says

I read the instructions several times now and since I cant get it right I asked because maby someone else saw where I went wrong, simple as that

As I said, I passed the exercise, the little box turned green, but it annoyed me that I passes even though it is wrong since it should have returned 22.5.

We’ve established that you need some kind of counter yes?
So you would need to find the instruction that says how to do that.
Have you done that?

If you have but you’re unable to follow it, then what’s stopping you?
If you haven’t, then you don’t need me to do those things

There are a whole lot of things I’m happy to help with but something is really off here
You’re asking for what sounds like is already in the instructions. Repeating instructions to you is not interesting and you’d help yourself better by just reading them and perhaps asking questions about them, but not by just asking someone to tell them to you again

Yes and in my code I got the counter

orderCount = orderCount ++;

Is there something wrong with the order counter

Why the rude tone? I really dont get how I was offensive by ask a question where I went wrong

This is how it looks if anyone else could see where I went wrong

Ok finally solved it, it was supposed to be orderCount ++; not ordercount = orderCount++;

What you’re doing appears rude to me, I need you to see that. I do not consider myself to be adding any rudeness here, merely explaining how what you’re doing here is received. I also understand that your perspective is different and that you don’t yet know how to approach this. The way you’re asking isn’t a good way to do so, for neither of us.

While your interest may be entirely to fix your code, I have no interest whatsoever in that. My interest is in increasing your ability to fix your code. If you have no interest in that then you’ll appear incredibly rude because that’s saying that you want it done for you and that you don’t want to learn. Our interests at that point have nothing in common.

If it isn’t explained what needs help with then that’s a whole lot like saying that the helpers time is worth less than that of the person asking. This leads to less chance of getting what’s wanted, a far less happy response and far less chance of being helpful. Overall really bad.

All you really need to do is share a way of reproducing what you currently have (note that you missed one line during pasting, that line was pretty significant to your problem because it defined the counter) and motivate why you aren’t able to solve the problem yourself so that others know what needs explaining.

And I thnk it was rude of you not to even read the headline where its clear what exersice it was and just time after time say “is this even a task why do you ask me” I never asked you if you dont want to answer just dont reply to the thread instead of just repeating “Go figure yourself”

But I’m not interested in solving the problem. Only in you solving it.
So I’m not interested in what you’re supposed to do, only in what’s stopping you from doing it.

People are going to help out for their own reasons. That reason is often something other than you finishing your code. Usually it’s to teach something, so “how do I figure this out” is most of the time a far more successful question than “how is this done”

What you were asking for sounded like it was already in the instructions and you did not motivate why you could not follow that.
My suggestion was therefore to read the instructions, along with questions about why you could not in case you weren’t just missing the obvious idea of reading the instructions

And right now what I’m looking for is to make you better at asking questions - again, probably not your immediate interest, but it is mine.

I didnt ask you to write my code, I had some code and it returned something and it returned wrong, so the question was simply why did it return 0 instead of 22.5

Right, and you had not defined the counter so there was no reason it’d print anything at all, the code which you had posted was gibberish, in a lot of languages the equivalent would just crash.

You could then note that - hey, in the real code, there’s another line that DOES define the counter. That was missing in what you posted.

So the counter would then be defined, but not increasing. That’d be an entirely different situation.

You could then add prints before and after the line that you meant was supposed to increase that counter, and observe that it did not, and perhaps then explain what the line was supposed to do and ask what you were missing about that.

You were using postfix increment (VAR++) which adds 1 to the value and then returns the original value. prefix increment would increase the value and return the value that has been increased, that would have had the desired effect.

Ok can I come up with a suggestion, instead you could have said something in the line with

"Hey have you checked that ordercount? is it supposed to be orderCount = OrderCount++?

I didn’t get as far, I would have to have guessed that there was more code than you showed.
It’s hardly fair to post part of the code and expect me to guess the rest.
The problem with the code as posted was that an undefined variable was being used.

I have the same problem. My code looks good, the website checkes all the boxes when I run it, but the output is 0 instead of 22.5. I do have orderCount variable defined as 0 at the top and orderCount++ in the takeOrder function. Still it remains 0. and still the website is fine with that. But I am not. Can’t see where I went wrong. Here is my code:

var orderCount = 0;

function takeOrder(topping, crustType) {
return('Order: ’ + crustType + ’ pizza topped with ’ + topping);

console.log(takeOrder(‘bacon’, ‘thin crust’));
console.log(takeOrder(‘ham’, ‘hand tossed’));
console.log(takeOrder(‘mushroom’, ‘deep dish’));

function getSubTotal(itemCount) {
return itemCount * 7.5;

Also, for the record I agree with gregorvaletti. Ionatan there is no need to make this complicated and uncomfortable. If your method of support isn’t helping, adjust or move on.