Global Scope wont let me test 4?


#1

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;
};
console.log(myNightSky());

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.


#2

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.


#3

Here’s the llink.

Learn JavaScript Scope

Thanks


#4

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.


#5

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;

#6

Ok,

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.

Brian


#7

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