Program Next Button

Program the app to go back to the start when the user reaches the end of the quiz.

Step 1

Program what happens when the NextButton is clicked. Get the event handler block for this event.

Step 2

When the NextButton is clicked, the following things should happen:

  • Increase the Index Variable by one
  • Change the picture, according to the PictureList Variable
  • Change the question text, according to the QuestionList Variable
    • To do this, create this code:

      The code uses the Index Variable to keep track of the question number. 

Step 3

Try the code on your phone now! Click the Next button to change the picture and the question. What happens if you keep pressing next?

Step 4

You got an error! This is because you got to the end of the list and the program didn’t know what to do.

To fix this error, use an If Statement block. You need a statement that says “If you get to the end of the quiz, then go back to the start”. Try this:

Step 5

Test the code again! The quiz will now go back to the start!