There’s a repeated UI notice block. Extract it into a reusable
MessageCardcomponent and use it inAppinstead of duplicating markup.
Clean code means fewer duplicates. Encapsulating repeating UI in a component makes changes and testing easier.
MessageCard with title and text props.MessageCard.App, replace the three blocks with three MessageCard instances.data-testid="message-card" to the root element.function MessageCard({ title, text }) {
return (
<article className="notice" data-testid="message-card">
<h3 className="notice__title">{title}</h3>
<p className="notice__text">{text}</p>
</article>
);
}App:
<MessageCard title="Success" text="Operation completed" />import React from 'react';
import './styles.css';
export function MessageCard({ title, text }) {
return (
<article className="notice" data-testid="message-card">
<h3 className="notice__title">{title}</h3>
<p className="notice__text">{text}</p>
</article>
);
}
export default function App() {
return (
<main className="challenge-container">
<section>
<MessageCard title="Success" text="Operation completed" />
<div style={{ marginTop: 16 }}>
<MessageCard title="Warning" text="Please check input" />
</div>
<div style={{ marginTop: 16 }}>
<MessageCard title="Error" text="Something went wrong" />
</div>
</section>
</main>
);
}Why this works: The repeating UI is encapsulated; duplication is gone, readability improves, and changes are centralized.
There’s a repeated UI notice block. Extract it into a reusable
MessageCardcomponent and use it inAppinstead of duplicating markup.
Clean code means fewer duplicates. Encapsulating repeating UI in a component makes changes and testing easier.
MessageCard with title and text props.MessageCard.App, replace the three blocks with three MessageCard instances.data-testid="message-card" to the root element.function MessageCard({ title, text }) {
return (
<article className="notice" data-testid="message-card">
<h3 className="notice__title">{title}</h3>
<p className="notice__text">{text}</p>
</article>
);
}App:
<MessageCard title="Success" text="Operation completed" />import React from 'react';
import './styles.css';
export function MessageCard({ title, text }) {
return (
<article className="notice" data-testid="message-card">
<h3 className="notice__title">{title}</h3>
<p className="notice__text">{text}</p>
</article>
);
}
export default function App() {
return (
<main className="challenge-container">
<section>
<MessageCard title="Success" text="Operation completed" />
<div style={{ marginTop: 16 }}>
<MessageCard title="Warning" text="Please check input" />
</div>
<div style={{ marginTop: 16 }}>
<MessageCard title="Error" text="Something went wrong" />
</div>
</section>
</main>
);
}Why this works: The repeating UI is encapsulated; duplication is gone, readability improves, and changes are centralized.
The code editor is intentionally hidden on mobile.
Believe me, it's for the best: I am protecting you from the temptation to code in less-than-ideal conditions. A small screen and a virtual keyboard are not the best tools for a programmer.
📖 Now: Study the task, think through the solution. Act like a strategist.
💻 Later: Sit down at your computer, open the site, and implement all your ideas comfortably. Act like a code-jedi!