Skip to content

Instantly share code, notes, and snippets.

@h-okay
Created April 9, 2024 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h-okay/823cd8b9054209bcbf53a16692004244 to your computer and use it in GitHub Desktop.
Save h-okay/823cd8b9054209bcbf53a16692004244 to your computer and use it in GitHub Desktop.
for _, question := range quiz.questions {
timer := time.NewTimer(time.Duration(quiz.timer.secondsPerQuestion) * time.Second)
fmt.Printf("Problem #%d: %s = ", question.id, question.question)
answerCh := make(chan string)
go func() {
var answer string
fmt.Scanf("%s\n", &answer)
answerCh <- answer
close(answerCh)
}()
select {
case <-timer.C:
fmt.Println("Time limit exceed!")
case answer := <-answerCh:
if answer == question.answer {
quiz.score++
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment