FAQs on the exercise Global Scope

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply () below!

Has anyone else noticed that even though you get the code 100% correct, it still gives syntax errors and says that you fail the instructions? I’ve had this problem in literally 99% of the lessons. This is EXTREMELY DISCOURAGING, makes me think i’m just absolutely horrible at coding because even when comparing the solution code to my own, i cannot see any mistakes.

Agreed. Wish it would at least let you know which parts or lines you have correct so far. I have to reveal the answer too early on for something so dumb or not even incorrect, and then I am not able to follow along and complete it.

Thank god i’m not alone, it’s a very sad thing. Maybe if we start a few different threads in the get help part, telling people to come to that thread to do just that so they can get help from the people who have already done it and learned what was needed and can help them understand. I have a horrible problem with string methods for this exact purpose. It would be nice if we could ‘talk’ CodeCademy into doing something along those lines. Sorry you’re having problems, I decided to gain more context by just looking at a few videos and just practicing with them, picking apart the error and going back to basics. If I can help at all, let me know.

Yeah! It just did it to me on #2 on loops as well. Urgh! I thought I saw a “report a bug” link on here somewhere but I would be more busy reporting that and not working lol
Also there was one I was trying to reset back to default to start over since it required editing the original syntax, it was one about mayo or guacamole I don’t remember. I closed and reset my browser, rebooted, still would not reset!! I had to reveal the answer to get it back. Very annoying.

I don’t get why they don’t have a thread on here for reports like this. Set it up so if a report gets enough ‘upvotes’ (each upvote being a person who had that problem) it gets submitted to someone with impact for review. Also, the “Get Help.” button at the bottom right of the screen has a “Reset Exercise” If you click that it should completely reset, just cut or copy your code and edit it after it’s reset.EDIT When i was having that problem, i ended up just opening a text editor and pasting it in there in case something happened, so, try that too lol

So, I’ve tried two scenarios with the code, and both passed. What I’m curious about is if ‘const’ is technically replacing having to write ‘function’. I think I’m getting it, but am worried I’m learning the wrong way to write code properly. I need help understanding the difference, if any, of the following two ways I wrote this:

I greatly appreciate the speedy reply. Just to regurgitate: your first example is a function. The second one is a variable containing a function, as well as the third. Is that right?

I’m just getting started learning the variations, and ways to use the code. I guess my biggest issue is to know when I should use one over the other… or when one way of writing the code is just another way of doing the exact same thing.

Variables are sometimes described as containers where objects are stored, but that is not accurate. Variables are names in a table that refer to a value somewhere in memory. The table will contain a name and an address or possibly object id that can be further traced to an address where the value or object is actually stored.

That is what is meant when we say, a variable refers to an object or value. The object itself is not named in typical expressions, but is named in a declared function.

Function expressions that use the function keyword behave exactly the same as declared functions and have the same properties, such as this, arguments and return, among others. Arrow function expressions do not have all those properties (as in, do not have this or arguments objects).

It gets a little more complicated once we progress into OOP, but we can save that until later. All the technical details are of no real importance at this point. More important to learn about scope, and perhaps hoisting as it relates to declared functions and variables.

Further on in your study you will come across three terms,

non-method functions
methods
constructors

Likewise, add this to your extra reading as you progress.

When do we use one or the other form? I would suggest we should not think subjectively about this question, even though it does come down to choice. When we can reduce a function to arrow syntax without breaking the behavior expected from the function, then go ahead and use it.

const foo = bar => bar;

The above is known as an identity function that returns the argument. It is written in its simplest form.

It will take a lot of practice and learning different usage cases to really nail down the criteria for choosing which form to use. When in doubt, just use a normal expression and when it comes time to refactor your code, decide then whether arrow syntax is appropriate (just as effective).

const foo = function (bar) {
return bar;
};

There are no real hard and fast rules, so don’t get too bent around thinking of it like that. Think mainly about what works for you.

Man, you have no idea how much I appreciate your answer! It not only helped me understand in more detail what I just learned, but encouraged me to keep plowing forward, without trying to dissect each ‘code granule’ and functionality.

Again, thank you for taking the time to help a newbie! It’s very much appreciated.