Challenge 4
by Andrew Nguyen¡ Module 04 - Conditional Rendering

Introduction
Not Attempted
NameProgress
Course outline
Not Read
Module 01 - Diving Into React
Not Attempted
NameProgress
Key Concepts
Not Read
Project: Pet Parade
Not Read
Challenge 1
Not Attempted
Quiz 1
Not Attempted
Module 02 - Components and Props
Not Attempted
NameProgress
Project: Profile Card Creator
Not Read
Key Concepts
Not Read
Challenge 2
Not Attempted
Quiz 2
Not Attempted
Module 03 - State and Effect
Not Attempted
NameProgress
Key Concepts
Not Read
Project: Magic Garden
Not Read
Challenge 3
Not Attempted
Quiz 3
Not Attempted
Key Concepts
Project: Weather Wardrobe
Challenge 4
Not Attempted
Quiz 4
Not Attempted
Module 05: Handling Events
Not Attempted
NameProgress
Key Concepts
Not Read
Project: "Interactive Quiz App"
Not Read
Challenge 5
Not Attempted
Quiz 5
Not Attempted
Module 06 - Lists and Keys
Not Attempted
NameProgress
Key Concepts
Not Read
Project: "Photo Gallery"
Not Read
Challenge 6
Not Attempted
Quiz 6
Not Attempted
Module 07 - Forms and Validation
Not Attempted
NameProgress
Key Concepts
Not Read
Project: "Registration Form"
Not Read
Challenge 7
Not Read
Quiz 7
Not Attempted
Module 08 - Lifting State Up & Composition vs Inheritance
Not Attempted
NameProgress
Key Concepts
Not Read
Project: "Weather Dashboard"
Not Read
Challenge 8
Not Attempted
Quiz 8
Not Attempted
0 / 470 XP

Overview:

In this challenge, you will enhance the "Weather Wardrobe" project by adding more interactive features. Specifically, you'll manually change the weather condition to see the corresponding outfit recommendation dynamically. This will deepen your understanding of conditional rendering and state updates in React.

Objective:

  • Learn how to render components conditionally based on state.
  • Practice updating state dynamically to reflect different conditions.

Instructions for the Interactive Code Block:

Step 1: Add More Weather Conditions

Expand the existing state to include more weather conditions.

// Inside WeatherWardrobe component
const [weather, setWeather] = useState('sunny');

// Add more conditions
const weathers = ['sunny', 'rainy', 'snowy', 'windy', 'foggy', 'stormy'];

Step 2: Conditionally Render Additional Outfits

Add conditional rendering for the new weather conditions.

let outfit;
if (weather === 'sunny') {
  outfit = <div className="outfit">🌞 Wear sunglasses and a t-shirt!</div>;
} else if (weather === 'rainy') {
  outfit = <div className="outfit">🌧ī¸ Don't forget your umbrella and raincoat!</div>;
} else if (weather === 'snowy') {
  outfit = <div className="outfit">❄ī¸ Bundle up with a warm coat and gloves!</div>;
} else if (weather === 'windy') {
  outfit = <div className="outfit">đŸŒŦī¸ A windbreaker and scarf will keep you cozy!</div>;
} else if (weather === 'foggy') {
  outfit = <div className="outfit">đŸŒĢī¸ Wear a reflective jacket!</div>;
} else if (weather === 'stormy') {
  outfit = <div className="outfit">🌩ī¸ Stay indoors and keep warm!</div>;
**Step 3: Experiment with Different Conditions**

Modify the weather state manually in your code to test different conditions and see the corresponding outfits.

// Example of changing the weather condition manually
setWeather('foggy'); // Set this line to different conditions and observe the changes

Step 4: Styling and Enhancements

Ensure that your wardrobe items and additional weather conditions are styled appropriately.

/* Add to your WeatherWardrobe.css file */
button {
  background-color: #007bff;
  color: white;
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  margin: 5px;
}

button:hover {
  background-color: #0056b3;
}

.outfit-container {
  margin-top: 20px;
  font-size: 18px;
}

Step 5: Explore and Experiment

Run your application and manually change the weather conditions. Observe how the outfit recommendations change based on the selected weather.

Next Steps:

  • Add More Weather Conditions: Add additional weather conditions like "drizzly" or "overcast" and their corresponding outfits.
  • Weather Icons: Include weather icons next to the outfits for a more intuitive user experience.
  • Animation: Add simple animations to make the outfit transitions smoother and more visually appealing.

By completing this challenge, you will solidify your understanding of conditional rendering in React and how state updates can dynamically change the rendered output. Enjoy customizing your Weather Wardrobe and see how creatively you can handle different weather scenarios!

Discussion

0 comments
Loading editor ...
Remember to be polite and report any undesirable behaviour

Category

Empty

Labels

Discussion has no labels

1 participant

user avatar

Priority

Notifications

You're not receiving notifications from this thread.
Loading...
Ready ...
Course Outline