Now that your quiz taker can select quiz options, the program needs to tell them whether they are most like outcome one or outcome two.
In this video you'll make the quiz keep track of which option the user clicked more and reveal the results by showing the appropriate backdrop.
In this example, the outcome one sprite is clicked twice and outcome two once.
The program displays the outcome one backdrop to reveal the quiz results.
To begin, track how often each sprite is clicked with a variable.
Select the outcome one sprite, click variable and choose make a variable.
Name the variable outcome one clicks and select okay.
Doing this adds new variable blocks to the data menu.
Drag a change outcome one clicks by one block under the when this sprite clicked event.
To see the value of outcome one clicks, click the checkbox next to the variable.
You should see a variable display on the stage.
Right now the value is zero because the sprite hasn't been clicked.
Click the flag, then the outcome one sprite.
Each time this sprite is clicked, the computer stores that count in the outcome one variable.
Next, program the variable to reset its value to zero when the quiz starts.
The variable should reset when the flag is clicked, so add a set outcome one clicks to zero block under the flag clicked event.
Try it out again.
The clicks reset to zero at the start of the program.
Now the outcome one clicks are counted, do the same for outcome two.
Click the outcome two sprite and choose make a variable.
Name it outcome two clicks.
Drag a change outcome two clicks by one block after the when this sprite clicked event.
Drag a set outcome two clicks to zero block under the when flag clicked block.
Okay, try it out.
Both sprites store the click count in a variable.
Now if the quiz taker has gotten to the fourth costume which is blank, then the backdrop should switch depending on which spite was clicked more.
To check if the quiz is at the fourth costume add an if block after the next costume block.
Choose an equals operator from the operators menu.
If the costume number equals four then the backdrop should change.
Click looks and a drag a costume number variable into the operator.
Then enter a four in the other side.
This now reads, if the costume equals number four then.
To test this add a switch backdrop to outcome one block.
Run the program and see if the backdrop changes after the first three questions are answered.
Great, it does.
Next, make the quiz switch back to the questions screen.
Add a switch backdrop to questions screen block at the start of the program and click the green flag to reset it.
You can now change the backdrop after three questions, but the backdrop change should match the sprite that received the most clicks.
To do this use an operator.
Add an if else statement inside the if statement you already programmed.
Then select operators and drag a greater than operator into the condition portion of the if else.
Next click variable and drag the outcome one clicks and outcome two clicks variables into either side of the condition.
If outcome one clicks is great than outcome two clicks then the program should switch the backdrop to outcome one.
Drag the switch backdrop to outcome one block into the if portion of the conditional.
Otherwise, or else, the program should switch the backdrop to outcome two.
Click looks and drag a switch backdrop to outcome two block into the else section.
Try it out by taking the quiz.
Now the backdrop changes to show the outcome of the quiz.
In the final step you'll program the title screen to appear then to switch to the questions screen.
Now it's your turn.
Create outcome one clicks and outcome two clicks variables.
Program the variables to change by one after each sprite is clicked and set the variables to zero at the start of the program.
Next check if the costume equals four after the outcome one sprite's costume changes.
Then if the outcome one clicks is greater than outcome two clicks, switch to the outcome one backdrop else, or otherwise, switch to the outcome two backdrop.
Finally set the backdrop to the questions screen when the flag is clicked.
- Create a variable for both outcome sprites.
- Program the variable to change and reset.
- Reveal the results to the user.
- Program the quiz to reset.