Global Scope

Here is my code for the exercise…

I wanted to use the one liner arrow function (because it is new to me and I want to get used to it) and I get the following errors…

Does the code contain a function named myNightSky() defined with const?
Did you write a console.log() statement beneath the close of the function block?
Did you pass the myNightSky() function to console.log() as an argument?

Am I drunk? I even get the expected output that it wants.

const satellite = 'The Moon';
const galaxy = 'The Milky Way';
let stars = 'North Star';

const myNightSky = () => `Night Sky: ${satellite}, ${stars}, ${galaxy}`;


Please post a link to the exercise you are on. Thanks.

While your code may be sound, it might not match the expectation of the SCT, which is generally quite narrow in scope.

1 Like

Here are the steps I have completed so far. I am on 4.

  1. At the top of sky.js, write two global variables using const, one named satellite set equal to ‘The Moon’, the other named galaxy set equal to ‘The Milky Way’.
  2. Using let, write another global variable name stars and set it equal to ‘North Star’.
  3. Below these variables, using const, write a function named myNightSky. Inside the function, include a return statement like this:
    return 'Night Sky: ’ + satellite + ', ’ + stars + ', ’ + galaxy;
  4. Beneath the myNightSky() function, use console.log() to log the value of myNightSky() to the console.

You’ll notice that the myNightSky() function is able to access the global variables without any problem since the variables are available globally.

Output from my code is…

Night Sky: The Moon, North Star, The Milky Way

Still, no link. We can only speculate what is expected or what is wrong without knowing the exact lesson. Please post a link. Thanks.

1 Like

Your code is using a template string but the SCT may be expecting concatenation as given in the instruction:

return 'Night Sky: ' + satellite + ', ' + stars + ', ' + galaxy;
1 Like

Thanks! Apparently it cannot be the one liner arrow function. My code produces the intended result but does not utilize the ‘function’ and ‘return’ keywords in initialization. Once I changed it, it worked.


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