Modestly asking for help with a Random Number Generator project


Last Updated: 2012-07-03 06:01:13
  1. FreneticFerret

    FreneticFerret New Member

    Alright so here is what I am trying to do. I want to click a button that will generate a number between 1 and 100 and then, I want the number to be displayed on the screen.

    I also want to create conditional text depending on the number. For instance, if the random number generated is between 1 and 19, I want it to say a specific sentence after the number is displayed. If the number generated is between 20 and 40, I want a different sentence to be displayed.

    I have been watching the MIT tutorials and trying to figure it out in the block editor to no avail. Any help would be greatly appreciated.

    Advertisement
  2. appinventor

    appinventor Active Member

    Create a label in the Screen Designer: Label1
    In the blocks editor, drag out Screen1.Initialize block and put a [Label1.Text to ][random integer ](1,100) block inside.
    When you run the app the number will display.
    ---
    To have different messages display, you need to learn how to use the if and if-else blocks and how to form the blocks for the condition (true or false).

    An example of the blocks needed for a number between 1 and 19 would be:

    [if condition]([and][Label1.Text >= 1][Label1.Text <= 19])
    [Label2.Text to ][ text "this is a small number."]
    :
    ]

Share This Page