diff --git a/14-arrays/06-challenge-moodly/challenge/main.go b/14-arrays/06-challenge-moodly/challenge/main.go new file mode 100644 index 0000000..6600f84 --- /dev/null +++ b/14-arrays/06-challenge-moodly/challenge/main.go @@ -0,0 +1,41 @@ +package main + +// --------------------------------------------------------- +// EXERCISE: Moodly +// +// 1. Get username from command-line +// +// 2. Display the usage if the username is missing +// +// 3. Create an array +// 1. Add three positive mood messages +// 2. Add three negative mood messages +// +// 4. Randomly select and print one of the mood messages +// +// EXPECTED OUTPUT +// +// go run main.go +// [your name] +// +// go run main.go Socrates +// Socrates feels good 👍 +// +// go run main.go Socrates +// Socrates feels bad 👎 +// +// go run main.go Socrates +// Socrates feels sad 😞 +// +// go run main.go Socrates +// Socrates feels happy 😀 +// +// go run main.go Socrates +// Socrates feels awesome 😎 +// +// go run main.go Socrates +// Socrates feels terrible 😩 +// --------------------------------------------------------- + +func main() { +} diff --git a/14-arrays/06-challenge-moodly/main.go b/14-arrays/06-challenge-moodly/solution/main.go similarity index 100% rename from 14-arrays/06-challenge-moodly/main.go rename to 14-arrays/06-challenge-moodly/solution/main.go diff --git a/14-arrays/10-challenge-moodly-2/challenge/main.go b/14-arrays/10-challenge-moodly-2/challenge/main.go new file mode 100644 index 0000000..b59c762 --- /dev/null +++ b/14-arrays/10-challenge-moodly-2/challenge/main.go @@ -0,0 +1,78 @@ +// For more tutorials: https://blog.learngoprogramming.com +// +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// + +package main + +import ( + "fmt" + "math/rand" + "os" + "time" +) + +// --------------------------------------------------------- +// EXERCISE: Moodly #2 +// +// This challenge is based on the previous Moodly challenge. +// +// 1. Display the usage if the username or the mood is missing +// +// 2. Change the moods array to a multi-dimensional array. +// +// So, create two inner arrays: +// 1. One for positive moods +// 2. Another one for negative moods +// +// 4. Randomly select and print one of the mood messages depending +// on the given mood command-line argument. +// +// EXPECTED OUTPUT +// +// go run main.go +// [your name] [positive|negative] +// +// go run main.go Socrates +// [your name] [positive|negative] +// +// go run main.go Socrates positive +// Socrates feels good 👍 +// +// go run main.go Socrates positive +// Socrates feels happy 😀 +// +// go run main.go Socrates positive +// Socrates feels awesome 😎 +// +// go run main.go Socrates negative +// Socrates feels bad 👎 +// +// go run main.go Socrates negative +// Socrates feels sad 😞 +// +// go run main.go Socrates negative +// Socrates feels terrible 😩 +// --------------------------------------------------------- + +func main() { + args := os.Args[1:] + if len(args) != 1 { + fmt.Println("[your name]") + return + } + + name := args[0] + + moods := [...]string{ + "happy 😀", "good 👍", "awesome 😎", + "sad 😞", "bad 👎", "terrible 😩", + } + + rand.Seed(time.Now().UnixNano()) + n := rand.Intn(len(moods)) + + fmt.Printf("%s feels %s\n", name, moods[n]) +} diff --git a/14-arrays/10-challenge-moodly-2/main.go b/14-arrays/10-challenge-moodly-2/solution/main.go similarity index 100% rename from 14-arrays/10-challenge-moodly-2/main.go rename to 14-arrays/10-challenge-moodly-2/solution/main.go