FAQ: Scope - Global Scope

I believe @ajax7318832924 is correct. The you must use a comma and you must also make sure you have the spaces in the correct place. It wants the string output to be exactly like their example.
', '

Hi, how about copying everything exactly as in the instructions, and still getting an error? :slight_smile:

Sorry for the big picture, I’m allowed only one per post :smiley:

The way you define the function does not matter, and it gives errors for every case.
Concatenation or interpolation has bearing on the outcome in this exercise.

So I would like to avoid showing the solution, and try to figure out what’s wrong, and why codecademy is so picky with this one. It’s annoying to say the least.

Any suggestions?

EDIT: OMG, I figured it out. So it turns out that you should not put the parameters in :laughing: . So now we know more ways to be wrong.

That’s right. This lesson is showing you that you can use variables that are defined in a global scope within a function WITHOUT inserting them as arguments through parameters.

const satellite = "The Moon";

const galaxy = "The Milky Way";

const stars = "North Star";

function callMyNightSky(){
  return 'Night Sky: ' + satellite + ', ' + stars + ', and ' + galaxy;


This shows the global variables being used inside the function. In order to insert the variables into the function as arguments you would have to define parameters for each variable. Then you wold need to use each variable as arguments during the function call. Doing this without causing an error would look like this.

const satellite = "The Moon";

const galaxy = "The Milky Way";

const stars = "North Star";

function callMyNightSky(satellite, galaxy, stars){       //here are the parameters being defined
  return 'Night Sky: ' + satellite + ', ' + stars + ', and ' + galaxy;

console.log(callMyNightSky(satellite, galaxy, stars)); //here are the variables being used as arguments

Seems like you already had it figured out. Happy coding.

i surely do not understand any of this, especially the reason for having commas inside the single quotes…anyone who can elaborate more? ill reallly appreciate

That is known as interpolation by concatenation. Static string values are concatenated with dynamic values (variables) and the commas are static strings so the finished result is grammatically correct.

You will learn a newer form of interpolation known as template literals which was introduced in ES2015.

return `Night Sky: $(satellite), ${stars}, and ${galaxy}`

Let’s just say i’m having a big problem on scopes, i’m really trying to understand but it doesn’t come out clear enough.

1 Like

i have the same problem, that’s make coding extreme.

Think of a function as having a two-way mirror, one we cannot see through from the outside but that can see everything from the inside. Functions, and blocks in general can see all the variables outside of themselves that reside in the outer scope, or scopes above them.

When we declare a variable with var, let or const it belongs to the scope it is declared in. In the case of let and const that also applies to any construct that has a code block such as, for, if, while, switch, and any others that take the form,

 keyword (condition or state) {
    // code body

The curly braces denote a block.

Very much likewise, I was incredibly discouraged. I googled and youtubed and couldn’t find much to explain so, I gave up and got the solution. Lo and behold, I had written the solution.

Can someone please tell me if we can use the prompt() function in ES6 just like in ES5 or if it is not possible , then is there any alternative? If so , then can you please tell me .

In ES6, you can still use the prompt() method. However, you will not be able to use it in the Codecademy lessons, because, the prompt() method is a property of the window object. The window object is only accessible in browsers (so when writing HTML, CSS, JS), however, Codecademy is using a “special” kind of JavaScript known as Node.js. You’ll learn Node.js in the future, but all you need to know for now is that Codecademy uses it to see the JS output right in the black panel to the right (the console) instead of the browser console (dev tools)

So basically, scope is where a variable can be accessed. It is basically where a variable is visible. If a variable is declared outside of a block, it is declared in the global scope. Variables declared in the global scope are known as global variables. Global variables can be accessed anywhere within our code, even in blocks!

That’s what I understood, but please correct me if I’m wrong

@ejgrace7 @densphynxlogan097296 Try changing '.' to ','.

Olá! a respeito de variáveis globais como elas podem ser acessadas por qualquer código incluindo em bloco; posso pensar que sao dados externos que uma vez buscado pela funcao podem ser utilizados internamente? e outra onde essas variaveis globais ficam armazenadas? tambem em memoria? obg

Everything is stored in memory, and globals are universally accessible from anywhere. It is external to all functions and blocks but still in the same overall namespace of which there is but the one. Scope refers to contained variable environments with closure around their variables restricting access from the outside.

1 Like