Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class _QuizPageState extends State<QuizPage> {
List<Icon> scoreKeeper = [];

void checkAnswer(bool userPickedAnswer) {
bool correctAnswer = quizBrain.getCorrectAnswer();

setState(() {
//TODO: Step 4 - Use IF/ELSE to check if we've reached the end of the quiz. If so,
//On the next line, you can also use if (quizBrain.isFinished()) {}, it does the same thing.
Expand All @@ -60,6 +58,8 @@ class _QuizPageState extends State<QuizPage> {

//TODO: Step 6 - If we've not reached the end, ELSE do the answer checking steps below 👇
else {
bool correctAnswer = quizBrain.getCorrectAnswer();

if (userPickedAnswer == correctAnswer) {
scoreKeeper.add(Icon(
Icons.check,
Expand Down
10 changes: 8 additions & 2 deletions lib/quiz_brain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ class QuizBrain {
void nextQuestion() {
if (_questionNumber < _questionBank.length - 1) {
_questionNumber++;
} else {
_questionNumber = -1;
}
}

String getQuestionText() {
return _questionBank[_questionNumber].questionText;
if (isFinished()) {
return 'Finished!\nTap any button to restart.';
} else {
return _questionBank[_questionNumber].questionText;
}
}

bool getCorrectAnswer() {
Expand All @@ -48,7 +54,7 @@ class QuizBrain {
//TODO: Step 3 Part A - Create a method called isFinished() here that checks to see if we have reached the last question. It should return (have an output) true if we've reached the last question and it should return false if we're not there yet.

bool isFinished() {
if (_questionNumber >= _questionBank.length - 1) {
if (_questionNumber == -1) {
//TODO: Step 3 Part B - Use a print statement to check that isFinished is returning true when you are indeed at the end of the quiz and when a restart should happen.

print('Now returning true');
Expand Down