-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
37 lines (29 loc) · 710 Bytes
/
Copy pathmain.go
File metadata and controls
37 lines (29 loc) · 710 Bytes
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
package main
import "github.com/mostlybob/LearnAboutTheUS/quiz"
import (
"fmt"
"io/ioutil"
)
func main() {
learnUs := quiz.CreateQuizFromJSON(GetQuizJson("LearnAboutTheUS.json"))
ShowAQuestion(learnUs)
}
func ShowAQuestion(quiz quiz.Quiz) {
question := quiz.GetRandomQuestion()
fmt.Printf("%d - %v\n", question.Id, question.Text)
fmt.Println("(press Enter to show answers)")
var input string
fmt.Scanln(&input)
for _, answer := range question.Answers {
fmt.Println(answer)
}
fmt.Println("")
}
func GetQuizJson(pathToJson string) string {
// read the whole file at once - it's not that big
data, err := ioutil.ReadFile(pathToJson)
if err != nil {
panic(err)
}
return string(data)
}