JavaScript Curriculum
Your First Component
easyInstead of building the coffee shop menu as raw HTML, you will build it as a MenuCard component. Write it once, use it for every item on the menu — no copy-pasting HTML.
Your First Component
A React component is a JavaScript function that starts with a capital letter and returns JSX. That is the whole definition. Everything else — props, state, hooks — builds on top of this foundation.
Component Anatomy
Click each part of this component to understand what it does:
Click any highlighted part of the component to learn what it does.
JSX Rules — The Six You Must Know
JSX looks like HTML but it is not. These differences trip up every beginner:
'class' is a reserved keyword in JavaScript. JSX compiles to JS, so all HTML attributes that clash with JS keywords are renamed: class → className, for → htmlFor.
<div class="card">
<div className="card">
Build a Component Live
Adjust the props and see the component and generated JSX update in real time:
function MenuCard({ name, price, emoji, featured }) { return ( <div className="card" style={{ background: '#1c2128' }}> <span className="emoji">{emoji}</span> {featured && <span className="badge">⭐ Featured</span>} <h3>{name}</h3> <p className="price">£{price.toFixed(2)}</p> </div> ) } // Usage: <MenuCard name="Espresso" price={2.5} emoji="☕" featured={true} />
Your Challenge
Write a MenuCard component: accepts name, price, emoji, featured props. Returns a div.card with the emoji in a span, name in h3, price formatted as £X.XX in p.price, and if featured is true — a span.badge with "⭐ Featured". Export as default. Use it three times in App with different props.
Challenge
Write a MenuCard component that accepts name, price, emoji, and featured props. It should render a div.card containing the emoji, an h3 with the name, a p.price with the formatted price, and conditionally a .badge span if featured is true. Export it as default.
Your First Component
easyInstead of building the coffee shop menu as raw HTML, you will build it as a MenuCard component. Write it once, use it for every item on the menu — no copy-pasting HTML.
Your First Component
A React component is a JavaScript function that starts with a capital letter and returns JSX. That is the whole definition. Everything else — props, state, hooks — builds on top of this foundation.
Component Anatomy
Click each part of this component to understand what it does:
Click any highlighted part of the component to learn what it does.
JSX Rules — The Six You Must Know
JSX looks like HTML but it is not. These differences trip up every beginner:
'class' is a reserved keyword in JavaScript. JSX compiles to JS, so all HTML attributes that clash with JS keywords are renamed: class → className, for → htmlFor.
<div class="card">
<div className="card">
Build a Component Live
Adjust the props and see the component and generated JSX update in real time:
function MenuCard({ name, price, emoji, featured }) { return ( <div className="card" style={{ background: '#1c2128' }}> <span className="emoji">{emoji}</span> {featured && <span className="badge">⭐ Featured</span>} <h3>{name}</h3> <p className="price">£{price.toFixed(2)}</p> </div> ) } // Usage: <MenuCard name="Espresso" price={2.5} emoji="☕" featured={true} />
Your Challenge
Write a MenuCard component: accepts name, price, emoji, featured props. Returns a div.card with the emoji in a span, name in h3, price formatted as £X.XX in p.price, and if featured is true — a span.badge with "⭐ Featured". Export as default. Use it three times in App with different props.
Challenge
Write a MenuCard component that accepts name, price, emoji, and featured props. It should render a div.card containing the emoji, an h3 with the name, a p.price with the formatted price, and conditionally a .badge span if featured is true. Export it as default.