-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuiz.go
48 lines (37 loc) · 1.28 KB
/
Quiz.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"bufio"
"fmt"
"math/rand"
"strings"
)
func PlayQuiz(words Words, scanner *bufio.Scanner, numWords int, correct *int) {
usedWords := make(map[string]bool)
for i := 0; i < numWords; i++ {
var word Word
for {
word = words[rand.Intn(len(words))]
if !usedWords[word.Word] {
break
}
}
usedWords[word.Word] = true
fmt.Println(string(colorCyan), "\nDefinition:", string(colorReset), strings.Join(word.Definition, ", "))
posStrings := make([]string, len(word.Pos))
for i, pos := range word.Pos {
posStrings[i] = string(pos)
}
fmt.Print(string(colorCyan), "Part of Speech: ", string(colorReset), strings.Join(posStrings, ", "), string(colorReset), "\n", string(colorCyan), "Sentance: ", string(colorReset), *word.EnglishSentence, "\n")
scanner.Scan()
input := scanner.Text()
if strings.EqualFold(strings.TrimSpace(input), word.Word) {
fmt.Print(string(colorGreen), "✔ Correct", string(colorReset), "\n")
*correct++
} else {
fmt.Print(string(colorRed), "❌ Incorrect, ", string(colorGreen), "Correct Answer: ", word.Word, string(colorReset), "\n\n")
if word.Description != nil {
fmt.Print(string(colorYellow), "Additional Information: ", string(colorReset), *word.Description, string(colorReset), "\n")
}
}
}
}