1.When the user clicks the button, our audio file will be played and a random side of the coin will be displayed. First of all, we have to include the code for the button:
2. Click on Sound and add:
3. Now, how do we code that a random side of the coin has to be displayed every time the user clicks? First, we need to insert an if statement to include our conditions. So, drag the “if then” block from the Control section and add “else”.
Then, we will use a random function so that the app will choose randomly between two numbers, one of each will make an image visible. For example, if the random number between 1 and 2 is 1, we want the app to display Image1. Go to Math and drag the block “….=….”. Then, drag the following block inside the first empty space:
random integer from 1 to 100
Then change “100” to “2”. Change the value of the second empty space to 1.
4. Now we have to set what happens when the random number is 1. Go to Image1 and drag:
set Image1.Visible to
From Logic, drag and attach the block “true”.
5. If image 1 is visible, the other one must be invisible. So, just copy and paste the “set visible” block and change Image1 to Image2 and true to false.