Think of something that you wish Authorware could do but it doesn't?  Let the our good friends at Macromedia know via the wishlist.

Please let us know if you find any of the materials on this site inappropriate or offensive. Please include the url and why the material should be reviewed.

Comments and questions about the site are also welcome. Please no Authorware questions, use the AWARE list.


B2012 - How do I generate two random numbers and ask the user to add them?

by - Joseph Ganci

I need to generate two random numbers, show them on the screen, then have the user type in their sum. After that, I need to show them whether they are correct or not. If they are not correct, they should keep trying until they get the answer correct.

Here's one way to do it.

The first Calculation generates two random numbers between 1 and 10 and places them in user variables rand1 and rand2:

rand1 := Random(1, 10, 1)
rand2 := Random(1, 10, 1) 

The Interaction icon shows the two random numbers and asks the user to type in their sum.  The text entry response waits for the user to type in the answer, after which the Calculation feedback executes the following script:

right := (NumEntry = rand1 + rand2)

This sets the user variable right to TRUE if the number the user types is equal to the sum of the two random numbers, otherwise it will be set to FALSE.  Since the text entry response is set to Continue branching, one of the two conditional responses that follow it will be executed, depending on the value of right. If the user gets the answer right, the contents of the Map icon executes with the following:

The Display icon tells them they got the answer right. The Wait icon waits for the user to click the Continue key on the screen. The Calculation icon contains the following script:

rand1 := Random(1, 10, 1)
rand2 := Random(1, 10, 1)
PresetEntry := ""

This generates two new random numbers and clears the text entry field.

If, on the other hand, the user had gotten the answer wrong, the final response will activate, telling the user the answer is wrong and to try again.

There are 0 reviews
Add your review