Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript One Solution

Keytron Brown
Keytron Brown
15,828 Points

I have done everything right and my code is still won't render to the browser. Please help.

// 1: Create a 'Planet' component that renders a planet card


const Planet = (props) => {
  return (
    <div className="card">
        <div>
          <img src={props.url} alt={props.name}/>
        </div>
        <h2>{props.name}</h2>
        <p>{props.desc}</p>
        <h3>Planet Profile</h3>
        <ul>
          <li><strong>Diameter:</strong> {props.diameter}</li>
          <li><strong>Moons:</strong> {props.moons}</li>
        </ul>
      </div>
      <div className="card">...</div>
  );
}
// 2: Create a container component that iterates over the planets array 
//    and renders a 'Planet' component for each object in the array 

const Planets = (props) => {
  return (
     <div className="container"> 

     {props.listofPlanets.map( planet =>
        <Planet
            name={planet.name}
            diameter={planet.diameter}
            moons={planet.moons}
            desc={planet.desc}
            key={planet.id}
            url={planet.url}
        />

     )}
     </div>
  );
}
// 3: Render the container component to the DOM

ReactDOM.render(
  <Planets listofPlanets={planets} />,
  document.getElementById('root')
);

2 Answers

Return a single parent element. You cannot return adjacent parent elements.

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,723 Points

You're getting an error in console Uncaught SyntaxError: http://port-80-rlnbu8pi7z.treehouse-app.com/app.js: Adjacent JSX elements must be wrapped in an enclosing tag (88:6)

To get rid of error and make page load:

const Planet = (props) => {
  return (
    <div className="card">
        <div>
          <img src={props.url} alt={props.name}/>
        </div>
        <h2>{props.name}</h2>
        <p>{props.desc}</p>
        <h3>Planet Profile</h3>
        <ul>
          <li><strong>Diameter:</strong> {props.diameter}</li>
          <li><strong>Moons:</strong> {props.moons}</li>
        </ul>
      </div>
      <div className="card">...</div>  // remove this div or wrap all tags in another div
  );
}