FAQ: Components and Advanced JSX - Put Logic in a Render Function

This community-built FAQ covers the “Put Logic in a Render Function” exercise from the lesson “Components and 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 Put Logic in a Render Function

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!

Hi, I don’t really understand why n has to declared in the render() for it to work.

It does not make sense logically if n is declared in the class component as it will always be a static value once the class component is called, but I would still expect it to run.

I copied the code to my IDE and it doesn’t run.

Hi everyone,

I was brushing up on my react stuff and when working through this particular exercise the last step:


At the bottom of the file, use ReactDOM.render() to render an instance of Friend . Use the example code as a guide.

I was wondering why my initial code wasn’t being accepted:

ReactDOM.render(<friend /> document.getElementById('app')

The error I was getting was that the first argument had to be <Friend />

however in the code I’d written (AND as per exercise instructions) the class has friend written in lower case;

// New component class starts here:

class friend extends React.Component {

  render() {

    const friend = friends[1];

    return (



      <img src={friend.src} />






is this a bug in the exercise or when calling the class to be rendered does it always have to be Capitalised?