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 trialtravis halarewich
9,165 PointsWill not render to web browser
With the code below I can not get it to render to the webpage. The only thing i've noticed is the code snippet
ReactDOM.render()
when looking at render() in workspace it is not have the proper syntax highlighting like it should. This leads me to believe there is something before it causing an issue for render() not to be recognized in turn not allowing it to show up in the browser.
// =============================================================
// WRITE YOUR CODE BELOW
// =============================================================
// 1: Create a 'Planet' component that renders a planet card
const Planet = (props)=> {
return (
<div className="card">
<div><img src={props.img} 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>
);
}
// 2: Create a container component that iterates over the planets array
// and renders a 'Planet' component for each object in the array
const Container = (props)=> {
return (
<div className="container">
props.planets.map( planet=>
<Planet
key={planet.id}
name={planet.name}
diameter={planet.diameter}
moons={planet.moons}
desc={planet.desc}
img={planet.url}
/>
)
);
}
// 3: Render the container component to the DOM
ReactDOM.render(
<Container planets={planets}/>, document.getElementById('root')
)
1 Answer
Ryan Beck
3,826 PointsHi, you're missing the curly brackets for the iterator in the container component (javascript expressions must be enclosed in curly brackets). Also, the div tag needs to be closed.
It should look something like this.
const Container = (props)=> {
return (
<div className="container">
{props.planets.map( planet=>
<Planet
key={planet.id}
name={planet.name}
diameter={planet.diameter}
moons={planet.moons}
desc={planet.desc}
img={planet.url}
/>
)}
</div>
);
}
Hope this has helped :)