@@ -27,27 +27,31 @@ function startGame(string $rules, int $roundCount, array $data): void
2727
2828 for ($ i = 0 ; $ i < $ roundCount ; $ i ++) {
2929 $ question = $ data ['questions ' ][$ i ];
30- $ correctAnswers = $ data ['correctAnswers ' ][$ i ];
30+ $ correctAnswer = $ data ['correctAnswers ' ][$ i ];
3131
32- questionAsk ($ question , $ correctAnswers , $ name );
32+ $ answer = questionAsk ($ question );
33+
34+ if (isCorrectAnswer ($ answer , $ correctAnswer )) {
35+ line ('Correct! ' );
36+ } else {
37+ gameOver ($ answer , $ correctAnswer , $ name );
38+ }
3339 }
3440
3541 line ('Congratulations, %s! ' , $ name );
3642}
3743
38- function questionAsk (string $ question, string $ correctAnswer , string $ name ): void
44+ function questionAsk (string $ question ): string
3945{
4046 line ($ question );
41-
42- $ answer = prompt ('Your answer ' );
43- isCorrectAnswer ($ answer , $ correctAnswer , $ name );
47+ return prompt ('Your answer ' );
4448}
4549
46- function isCorrectAnswer (string $ answer , string $ correctAnswer, string $ name ): void
50+ function isCorrectAnswer (string $ answer , string $ correctAnswer ): bool
4751{
48- if ($ correctAnswer !== $ answer ) {
49- gameOver ($ answer , $ correctAnswer , $ name );
52+ if ($ correctAnswer === $ answer ) {
53+ return true ;
54+ } else {
55+ return false ;
5056 }
51-
52- line ('Correct! ' );
5357}
0 commit comments