Use export to Reuse a Code Block

Use export to Reuse a Code Block
0

#1

Tell us what’s happening:

Please help, Im not understanding why this is not a valid export.

Your code so far


"use strict";
const foo = "bar";
const boo = "far";
export { foo }

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-export-to-reuse-a-code-block


#2

It is valid, but that isn’t what it’s asking you to do:

Below are two variables that I want to make available for other files to use. Utilizing the first way I demonstrated export, export the two variables.


#3

I guess I’m hitting a brick wall then.
I’m not understanding what to do.


#4

Take another look at the hint in the instruction.

export { capitalizeString } //How to export functions.
export const foo = "bar"; //How to export variables.

#5

I’ve tried

export const foo = “bar”;

and it doesnt work


#6

That’s the right code. So try closing your browser and if that doesn’t work, the delete cookies. Sometimes the database gets corrupted.


#7

“use strict”;
const foo = “bar”;
const boo = “far”;

export const foo = “bar”;

Cleared cache and cookies, still isnt working.


#8

I think I see the issue now. You are declaring the variable and then exporting. Just do it on one line.

So not

const foo = "bar"
export const foo = "bar"

Just

export const foo = "bar"

If you open up devtools, you’ll see the error in the console.

On chrome, right click over the instructions panel, select inspect, then choose the console tab.


#9

Thank you so much. It was racking my brain.
Second time I tried just running
export const foo = “bar”
Nothing would happen.
I had deleted “use strict”;


#10

Your welcome. Remember to use the console as your first step in troubleshooting. It has saved me countless hours once I discovered it. You can also write console.log statements to it to see what you’re code is doing.


#11

Deleting “use strict” is not the answer.

I finally figured it out.

Final hint: don’t add any new lines of code. Only modify existing lines.

Solution:

"use strict";
export const foo = "bar";
export const boo = "far";

I hope FCC collects data on lessons submission attempts so they can see a spike and fix lessons like this one that have unclear instructions and/or overly strict rules.


#12

Good job on solving this. It would be easier and better for you to just submit an issue about the unclear instructions. Do you know how to do that?


#13

Do you mean https://github.com/freeCodeCamp/freeCodeCamp/issues?


#14

Yes, exactly! It’s how FCC has developed and grown.


#15

Just as a note, const can’t be redeclared. You can’t have const foo = then a few lines later const foo =, which is what you were doing. That’s why you need to just export const foo =, otherwise JS will correctly notice you’ve made and error, and will refuse to work.


#16

Thanks, you’re a life saver. Been on this for a while now wondering why it’s not working.


#17

Exactly getting “Duplicate declaration error in the console”


#18

Solution:

“use strict”;
export const foo = “bar”;
export const bar = “foo”;


#19

I did the same thing,but couldn’t pass out.

“use strict”;
export const foo = “bar”;
export const bar= “foo”;
this was my code snippet…
Can’t find the reason,can you help please;


#20

I was running into the same issue. What seemed to fix it for me was I added a space between “bar” and “=”.

From this:
“use strict”;
export const foo = “bar”;
export const bar= “foo”;

To This:
“use strict”;
export const foo = “bar”;
export const bar = “foo”;