Global Scope wont let me test 4?

Test 4 instructions:
"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."

This is my code which logs properly to the console:

const satellite = 'The Moon';
const galaxy = 'The Milky Way';
let stars = 'North Star';
function myNightSky() {
  return 'Night Sky: ' + satellite + ', ' + stars + ', ' + galaxy;

The red error at bottom of screen reads:
“Did you write a console.log() statement beneath the close of the function block?”

I am fairly certain my console.log statement is in fact below the function block.

Any help greatly appreciated.

Please post a link and we’ll have a look at the exercise. In lieu of there being a very limited number of responses, the above response may not have anything to do with the actual problem. Ultimately, the SCT expects to see a certain code pattern, and barring that is issuing an error message.

1 Like

Here’s the llink.

Learn JavaScript Scope


1 Like

The task is asking you to start the function with const. So it is looking for

const myNightSky = () => {
return 'Night Sky: ’ + satellite + ', ’ + stars + ', ’ + galaxy;

but your function starts with function. Also, when you refactor the arrow function you remove the arrows as you did but also you no longer use the return keyword.

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;


I see where I should have created the function using const instead. That was part 3 so my confusion came because it passed me on that section then dinged me on part 4 by claiming my console.log wasn’t below the close of the brackets. Oddly enough, without changing a single line of code it now passes all 4 tests. I do appreciate the feedback on my not following the part 3 directions properly.



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