Created
April 9, 2024 13:00
-
-
Save h-okay/823cd8b9054209bcbf53a16692004244 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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