top of page

Multiplication quiz

This tutorial provides instructions how to create a Scratch Multiplication Quiz.

The quiz will consist of 10 questions where a user will be asked to choose one of 4 answers.

m1.PNG

See below definitions of the terms we will use (from https://www.basic-math-explained.com/product-multiple-factor.html#.Wv3CM4gvzFg)

m2.PNG

In this case 20 is the product of 4 and 5.

Step 1

Start with opening Scratch editor and choosing 5 characters sprites. It could be Robot1, Giga, Nano, Tera and Pico or any other.

m3.PNG

Place first sprite at the top and the rest in line at the bottom (like on the picture in the Overview).

Step 2

Let’s create a variable that will store factors.

m4.PNG

Then initiate the variable with a random value between 2 and 12. This should happen every time the “space” key is pressed and in the context of the top sprite (Robot1).

m5.PNG

Test your code.

Step 3

Now let’s create 4 valid multiples.

To store multiples we will need a list. You can think about a list as an ordered set of variables.

Go to Data and create a list called “Products”. Make sure it’s accessible for all sprites.

m6.PNG

You should see an empty list in the main window.

 

Now let’s create 4 multiples using “insert”, “random” and “*” blocks.

You will also need a “repeat” loop which executes 4 times.

m7.PNG

Test the code. You should get four numbers that are multiples of value stored under the “factor” variable”.

Step 4

Did you notice that every time you press “space” the old values stay in the list, just being pushed out further down?

We don’t need them so let’s clean up the list…

Add “Delete (all)” block from the data blocks.

m8.PNG

Test the code.

Step 5

We will now make our characters say the actual products from the list.

Click on first of the bottom sprites and insert following code:

m9.PNG

This code will be executed at the same time as the script we created previously so we need as short delay (“wait” block) to allow the list to be populated.

 

Test your code. The sprite on the bottom left should say the first element of the list.

 

Now copy this code to the three other sprites (to do it, simply drag and drop to code on the sprite). For each sprite, change the item parameter so that sprite 2 reads second item of the list and so on.

 

Test your code. You should have all four values displayed like below

m10.PNG

We don’t need to see the list anymore so let’s hide it by removing tick from the list block

m11.PNG

Step 6

This step is about making one of the products invalid.

To do this we will randomly choose one of the products and then add to it a number bigger than zero but smaller than the base factor.

For example if the factor is 5 and product 25 then the code would randomly choose from following values: 1;2;3;4. Let’s say the random block chooses 3 so the new invalid product value would be 28 (25 + 3).

 

To code it let’s firstly create a variable WrongProductId.

m12.PNG

Now, the tricky two lines of code and one more with user instructions

m13.PNG

Test your code. One of the answers should always be wrong.

Step 7

Getting answers and tracking score.

Start with adding a new variable - Score.

m14.PNG

Score needs to be zeroed everything we start the quiz so will need a new script that is triggered after green flag is pressed. You can add some instruction for the user at the end of this section.

m15.PNG

Users will be pressing keys 1,2,3 or 4 to point the wrong multiple.

The code below will increase the score if user presses 1 and the wrong product id is also 1.

Add this code still in the context of the top sprite.

m16.PNG

Step 8

In similar way we should handle keys 2,3,4 but instead of copying the code three times we will define a new block and save some space :)

 

Go to “More blocks” and name the new block “Analyse answer”. Choose number input from Options.

m17.PNG

Now move the code from “when key 1 pressed” to the new block definition. Replace “1” in the if statement with “number1”.

m18.PNG

Put the new “Analyse answer” block under events representing all 4 keys

m19.PNG

Test your code. Is the score incremented correctly?

Step 9

Let’s end the quiz after 10 questions.

 

Add a new variable and name it “question”

m20.PNG

Reset the variable at the beginning of the quiz

m21.PNG

“Question” should be increased every time a new question is asked.

We also need an “if else” condition where new question is prepared only if did not reach maximum number of questions.

m22.PNG

Make sure only the score variable is visible in the main window:

m23.PNG

Test your program - it’s should be all done now.

 

For reference, all the main sprite code below:

m24.PNG

Challenge 1

Can you add sounds after correct and wrong answers?

Challenge 2

Can you enable users to answer by clicking on sprites rather then pressing keys?

Hint: you might do this using “broadcast” blocks.

Challenge 3

Can you ensure all the products are unique for a question?

Hint: you might need a new variable and replace the Repeat block with a different type of loop..

© 2021 by OhSnapCoders & Pawel Wasilewski. Proudly created with Wix.com

  • Facebook Social Icon
  • Twitter Social Icon
  • Google+ Social Icon
bottom of page