FAQ: Advanced JSX - Variable Attributes in JSX

This community-built FAQ covers the “Variable Attributes in JSX” exercise from the lesson “Advanced JSX”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Learn ReactJS: Part I

FAQs on the exercise Variable Attributes in JSX

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I’m currently stuck with the error message “gooseImg should be equal to an element.”
My code:

import React from ‘react’;
import ReactDOM from ‘react-dom’;

const goose = ‘https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-goose.jpg’;

// Declare new variable here:
const gooseImg = (

);

My variable gooseImg seems to be equal to an img element. Am I missing something or is this a bug?

import React from ‘react’;
import ReactDOM from ‘react-dom’;

const goose = ‘https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-goose.jpg’;

// Declare new variable here:
const gooseImg = ();

ReactDOM.render(gooseImg, document.getElementById(“app”));

According to codes above, why at ReactDOM.render’s first parameter,
gooseImg does not need curly braces?

Why doesn’t this work for the first step?

const gooseImg = (

);

1 Like

Like it definitely does work and even follows your example, and after adding the rest from part 2 it correctly displays the image?

const gooseImg = (

);

ReactDOM.render(gooseImg, document.getElementById(‘app’));

I also had another issue in a previous course where I missed a comma, but it said I passed (green check box) even though it didn’t display the 2 + 3??? Do you guys test these courses?

It’s worth mentioning when curly braces are used to set attributes, the original quotes are dropped.
While this is obvious in 7th step (all attributes are string), it’s the same for event handlers.

<... onclick="handler();"...>

becomes

<... onClick={handler}...>
3 Likes
const gooseImg = <img src={goose} />;

You have to put the img inside,
and write it in one line, otherwise it doesnt accept it.
What is a bit stupid, as in the last exercise it was written that if we put it on more lines its more readable.

Yes, exactly, I assumed it is just this practice that does not accepts this syntax even though it is correct.

You need to write it on one line which is sort of dumb when the exercise tells us to do multiple lines to make it look more legible.

Yeah that threw me because my instinct was to write:

const gooseImg = <img src="{goose}" />;

…which threw an error. It would have been nice for them to say why this is the case.