Lesson 1 of 39
Lesson Progress: 0%
Instructions
▼ ← Click the triangle to hide or reveal instructions.if (isLoggedIn) line checks whether the user is logged in.isLoggedIn is true, the code shows Welcome back!.Please log in. instead.Instructions
▼ ← Click the triangle to hide or reveal instructions.function Message().&& symbols mean “only show this if the value on the left is true.”{hasNotification && <p>You have a new notification.</p>} shows the message only when hasNotification is true.Instructions
▼ ← Click the triangle to hide or reveal instructions.WelcomeMessage.function Name(), but this one uses const WelcomeMessage = function ().=>.&& symbols mean “show this only if the first part is true.”{isLoggedIn && <p>Welcome back!</p>} are needed so JavaScript logic can work inside the JSX.Instructions
▼ ← Click the triangle to hide or reveal instructions.SaleBanner.function Name(), but this one starts with const SaleBanner = function ().=>.&& symbols mean “only show this if the part on the left is true.”{hasDiscount && <p>Today’s discount is available.</p>} are needed so JavaScript can work inside the JSX.Instructions
▼ ← Click the triangle to hide or reveal instructions.function Name(), but this example uses an arrow function with () =>.&& symbols can be used to show something only when a value is true.{isLoggedIn && <p>Welcome back!</p>} shows the welcome message only when isLoggedIn is true.{} are needed so JavaScript logic can be written inside the JSX.Instructions
▼ ← Click the triangle to hide or reveal instructions.function Name(), but this example uses an arrow function with () =>.&& symbols can be used to show something only when a value is true.{hasError && <p>There was an error submitting the form.</p>} shows the error message only when hasError is true.{} are needed so JavaScript logic can be written inside the JSX.Test Incomplete
function Greeting() {
const isLoggedIn = true;
if (isLoggedIn) {
return <h1>Welcome back!</h1>;
} else {
return <h1>Please log in.</h1>;
}
}
render(Greeting);function Message() {
const hasNotification = true;
return (
<div>
<h1>Dashboard</h1>
{hasNotification && <p>You have a new notification.</p>}
</div>
);
}
render(<Message/>);const WelcomeMessage = function () {
const isLoggedIn = true;
return (
<div>
<h1>Home</h1>
{isLoggedIn && <p>Welcome back!</p>}
</div>
);
};
render(<WelcomeMessage/>);const SaleBanner = function () {
const hasDiscount = true;
return (
<section>
<h2>Store</h2>
{hasDiscount && <p>Today’s discount is available.</p>}
</section>
);
};
render(<SaleBanner/>);const WelcomeBanner = () => {
const isLoggedIn = true;
return (
<div>
<h1>Home</h1>
{isLoggedIn && <p>Welcome back!</p>}
</div>
);
};
render(<WelcomeBanner/>);const ErrorMessage = () => {
const hasError = true;
return (
<section>
<h2>Form</h2>
{hasError && <p>There was an error submitting the form.</p>}
</section>
);
};
render(<ErrorMessage/>);