Assigning a variable within a function body


Hi. I’m an absolute beginner to JavaScript. I’m actually working in the Scope section, but was instructed to create a locally scoped variable in order to mask a globally scoped one.

the globally scoped variable was
let starts = “North Star”;

Instruction was to assign “Sirius” locally in the first line of a function including the stars function. So I wrote:

const myNightSky = () => {stars = "Sirius"; return "Night Sky: " + satellite + ", " + stars + ", " + galaxy; }

I’m getting an error message. What did I do wrong? The program shows no hints. Thanks.


Can you share the exercise url? Are satellite and galaxy defined?

You could add a function call, so the function actually executes, this might show the error


Hi @fangchuan1911,

While waiting for you to provide the relevant information asked by @stetim94, I am wondering whether this spelling mistake plays a part in your getting an error situation, look below in bold:

Did you mean that?

If you still having trouble, a link to the exercise, your written full code in the exercise, what error message it is showing, all that would be very much needed for others to help you.


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