Quiz App - B

22

In this lesson you will complete several small programming projects that add enhancements to the Quiz app. You are encouraged to discuss your ideas for how to solve these problems with the instructor and with your partner and other students.

Objectives

  • learn to count actions (right/wrong answers) using a list to keep track of which questions have already been answered

  • learn to use loops with listscheck for the end of the list

  • solidify your understanding of the quiz app through personalizing and customizing it

Loops with Lists

Two main types of loops can be used to step through each item in a list. A for each number Loop uses a variable called number (often renamed as i) as the index of the loop; this variable starts at 1 and is incremented by 1 each time through the loop until it reaches the length of the list. In the following for loop, the select list item block is used to find the item at that index indicated by number and to speak it using the TextToSpeech block.


There is also a for each item in list loop that selects each item in the list and assigns it to the variable item. This is simpler to use with lists but it does not keep track of the index. If you need the index, you can use a index in list block or use a for loop like above. You will need to use one of these loops with lists in the mini project #2 below.



AP PSeudocode

In the CSP AP exam questions, the following pseudocode is used for a for each item in list loop:


Notice below, that the square brackets [ ] are used to select a list item from the list using the index i.

Also, check out the other CSP pseudocode relevant to lists on the third page of the reference sheet.

Getting Ready

  • Open App Inventor and open your Quiz App A to continue on. If you don't have a solution to the Quiz App A, you can start App Inventor and upload the Quiz App Projects Template.

  • After opening your Quiz project or the template, rename it QuizProjects2, or QuizB , or something similar to that (Save project as...). Then complete the programming exercises described below.

0. Fix the User Interface: In order to keep the UI consistent there are a few fixes you can implement

    • Clear answers for users.

      • Instead of making users delete the textbox manually, whenever a question changes, the textbox should clear automatically.

    • Grey is boring. Neon is horrible. Create a nicely complementary, professional, appealing color theme.

    • Refactor your code to put displayQuestion in a procedure that can be called from the search button, the next button, and from screen initialize once the index is set.

1. If/Else Scoring Algorithm: Modify your app to keep score of how many questions are answered correctly and incorrectly. Be sure and restrict it so that the quiz taker can only receive credit for answering each question once (i.e., if there are three questions, the quiz taker can only be credited with three correct answers).

    • Hint: define a list of true/false (booleans) values to record whether or not each question has already been answered correctly.

    • Use the alreadyAnswered list of booleans to keep track of which questions users have already gotten points for:

    • SENTENCE-TO-CODE: if that question has not already been answered correctly (select list item)

      • then update the score (add 1)

      • replace item in list with true.

2. Loop Algorithm for Search: Add a keyword search capability to your app. For example, if the user types in NASA and clicks on the search button, you should find the question or answer with the word NASA in it and show that question. This will be a linear search through the parallel question and answer lists using a loop. Here are the steps to this project:

    • Add a TextBox for the user to type in a search word and a Button in a horizontal arrangement at the top of your app's UI.

    • SENTENCE-TO-CODE: When the search button is clicked, add a loop that steps through the lists using a loop counter i for the index of the loop.

    • Inside that loop, you will need an if statement and contains text blocks from the Text drawer to test if the search word typed in by the user is in each question or answer.

      • Note: use UPCASE when comparing texts.

    • SENTENCE-TO-CODE: If the search word/text is in the question, you should set the global variable index to the loop counter i, and then display the question at that index using your refactored procedure displayQuestion.

3. Use the Quiz App as a template to create a quiz on a topic of your own choosing. Besides changing the questions, answers, and pictures, add at least one more enhancement to the app. Be creative!

    • Possible enhancements:

      • Text to speech

      • Sound

      • Share button to share score

      • hints

      • count number of misses

      • restart button