24 — Quiz: asking questions and marking them
A quiz is one thing done once per question — ask it, compare the reply with the answer, add a point if it matches. Keeping the questions and the answers in two lists side by side makes adding a question one more line in each list.
Steps
Put the questions and answers side by side. The same places belong together:
run it →set questions to list of the capital of Korea, the largest ocean set answers to list of Seoul, Pacific show the first of questions show the first of answersthe capital of KoreaandSeoul.Go through the questions and take the answer from the same place:
run it →set questions to list of the capital of Korea, the largest ocean set answers to list of Seoul, Pacific for each question in questions with place set answer to item place of answers show question show answer endAsk, then compare. A name after
askis used as the question itself:
run it →set question to the capital of Korea set answer to Seoul ask reply question if reply equals answer show that is right else show that is not right show answer endAdd a point for each right answer. The score starts at nothing:
run it →set score to 0 add 1 to score add 1 to score show scoreYou get
2.The whole thing:
run it →set questions to list of the capital of Korea, the largest ocean set answers to list of Seoul, Pacific set score to 0 for each question in questions with place set answer to item place of answers ask reply question if reply equals answer show that is right add 1 to score else show that is not right show answer end end show score
Try it yourself
Add another question and another answer — to both lists, or the places stop
lining up. Then put show how many questions at the end so the score reads as
"so many out of so many".
What you learned
- Two lists side by side pair each question with its answer by place.
- A name after
askbecomes the question that is shown. if … equalsandelsesplit what happens on a right and a wrong answer.- A score starts at
0and goes up withadd 1 to score.