Implement Weather Advice Switch

GolangGolangBeginner
Practice Now

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.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL go(("Golang")) -.-> go/DataTypesandStructuresGroup(["Data Types and Structures"]) go(("Golang")) -.-> go/FunctionsandControlFlowGroup(["Functions and Control Flow"]) go/DataTypesandStructuresGroup -.-> go/strings("Strings") go/FunctionsandControlFlowGroup -.-> go/if_else("If Else") go/FunctionsandControlFlowGroup -.-> go/switch("Switch") subgraph Lab Skills go/strings -.-> lab-436449{{"Implement Weather Advice Switch"}} go/if_else -.-> lab-436449{{"Implement Weather Advice Switch"}} go/switch -.-> lab-436449{{"Implement Weather Advice Switch"}} end

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 weatherAdvice that takes a string argument (the weather condition).
  • Use a switch statement to provide recommendations for at least four weather conditions: snow, rain, sunny, and cloudy.
  • Include a default case for unrecognized conditions.
  • Print specific clothing advice for each condition using fmt.Println().

Requirements

  • Implement the weatherAdvice function in ~/project/weather_advice.go.
  • Use the provided main function to test the weatherAdvice function.
  • coat must be included in the advice for snow conditions.
  • umbrella must be included in the advice for rain conditions.
  • sunglasses must be included in the advice for sunny conditions.
  • jacket must 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!
โœจ Check Solution and Practice

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.