add: moodly challenges docs
This commit is contained in:
41
14-arrays/06-challenge-moodly/challenge/main.go
Normal file
41
14-arrays/06-challenge-moodly/challenge/main.go
Normal file
@ -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() {
|
||||||
|
}
|
78
14-arrays/10-challenge-moodly-2/challenge/main.go
Normal file
78
14-arrays/10-challenge-moodly-2/challenge/main.go
Normal file
@ -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])
|
||||||
|
}
|
Reference in New Issue
Block a user