Solution Review: Map the Days
This lesson discusses the solution to the challenge given in the previous lesson.
package mainimport ("fmt")var Days = map[int]string{1:"Monday",2:"Tuesday",3: "Wednesday",4: "Thursday",5: "Friday",6: "Saturday",7: "Sunday"}func findDay(n int) string {val,isPresent := (Days[n])if isPresent{ // what if key is not presentreturn val}else{return "Wrong Key"} // return wrong key if invalid key}func main() {n := 4fmt.Println(n,":",findDay(n))n = 0fmt.Println(n,":",findDay(n))}
Get hands-on with 1400+ tech skills courses.