Introduction
In this challenge, as a junior software developer at a mobile app startup, you'll create a personalized weather recommendation feature that helps users choose appropriate clothing based on current weather conditions. You'll implement a Go program that uses a switch statement to provide clothing recommendations for different weather conditions, including snow, rain, sunny, and cloudy.
Implement the Weather Advice Function
Your task is to implement the weatherAdvice function using a switch statement to provide appropriate clothing recommendations for different weather conditions.
Tasks
- Write a function
weatherAdvicethat takes astringargument (the weather condition). - Use a
switchstatement to provide recommendations for at least four weather conditions:snow,rain,sunny, andcloudy. - Include a
defaultcase for unrecognized conditions. - Print specific clothing advice for each condition using
fmt.Println().
Requirements
- Implement the
weatherAdvicefunction in~/project/weather_advice.go. - Use the provided
mainfunction to test theweatherAdvicefunction. coatmust be included in the advice for snow conditions.umbrellamust be included in the advice for rain conditions.sunglassesmust be included in the advice for sunny conditions.jacketmust be included in the advice for cloudy conditions.- The default case should print a message indicating that the weather condition is not recognized.
Example Output
When you run the program, the output should look like this:
go run weather_advice.go
--- Testing Weather Advice Function ---
For condition: Snow
Remember to wear a warm coat and snow boots! 🧣
For condition: Rain
Don't forget your umbrella and waterproof jacket! 🌂
For condition: Sunny
Wear sunglasses and light clothing! ☀️
For condition: Cloudy
A light jacket might be a good idea. ☁️
For condition: Unknown
Weather condition not recognized. Stay prepared!
Summary
In this challenge, you implemented a Go program that uses a switch statement to provide personalized weather-based clothing recommendations. You modularized your solution into a separate function (weatherAdvice) and tested it using a series of predefined test cases. This exercise helped reinforce your understanding of switch-case syntax, function definitions, and control flow in Go.



