Short-term memory: simple and quick question!


Nothing in the following code is incorrect, but I'm unclear as to why return true; is necessary for this particular exercise. I'm looking back through my notes on previous chapters and I'm not able to find an explanation. Does any one have some insight?

var cashRegister = {
    total: 0,
//insert the add method here    
    add: function(itemCost){ += itemCost;
    scan: function (item) {
        switch (item) { 
        case "eggs": 
        case "milk": 
        //Add other 2 items here
        case "magazine":
        case "chocolate":
    **return true;**
//Scan 2 eggs and 3 magazines
//Show the total bill
console.log('Your bill is ';


What breaks without it? (don't assume that it's necessary, people won't agree with the premise of your question)

If you've got code that lacks purpose, remove it


Nothing breaks without it!

Apologizes for not being clear as to why I originally stated "it's necessary". I said this because it was part of the original code Codecademy included in this particular exercise and it gave no instructions to modify it. For that reason I made the assumption that it was necessary yet observed nothing happened when I removed it, hence my question!


I'm mostly suggesting a more sceptical mindset. If you don't see/understand it yourself, don't accept it


Understood! Thank you for the push to continue to question and structure code in a manner that works and makes sense to me.


While I appreciate your input, would you be so kind as to address the question I asked?

Why did Codecademy include the portion of code I mentioned earlier? I believe it would be more efficient for me and anyone else attempting to learn JavaScript to not simply dismiss something just because I don't see it or understand it; we should also ask why.


No really, I think it's fine to dismiss stuff (what matters isn't what you don't learn, but what you do learn) - you'd catch up to any such thing eventually anyway

I agree with you as far as that it would be better if it wasn't there to distract you

You didn't ask it until now. (Or you kind of did, but under a false premise, invalidating the question)

I could make a few decent guesses about how it came to be there, but the only thing that matters is that it has no effect. Reason about it yourself instead - how is the return value of that function used?


Understood! Thank you for the advise in how I should be learning JavaScript, i.e., "what matters isn't what you don't learn, but what you do learn". This is an interesting perspective and one I certainly haven't been adopting thus far; I've spent much more time in my learning process of JavaScript trying to understand why things are being done a certain way according to Codecademy instead of just building off of what I have learned. This approach has most definitely sent me down many roads that may answer my questions (after hours of research), but ultimately changes nothing in regards to how I apply code. The question I have prompted here has actually demonstrated exactly that (How ironic! Haha!).

Without getting into the nitty-gritty details, I have discovered that return true is often used by those who are using functions in events (buttons, filling out forms, inputs, etc.). In these events return true or even return false are used to allow the event to either continue (true) or stop (false). In other words, the application of this code is pointless to this exercise or the proposed real-life scenario of this exercise.

It'll take me a little while to wrap my head around your suggested approach as it is counter-intuitive to my nature, but I'll get there. Thanks again!


Definitely don't read in too much on what cc does or says, they're not very rigorous. I like to view it as easy-to-consume demonstrations of how to use a couple of languages, and then when you've got the loops and functions etc you're well enough equipped to take on other resources


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.