PHP Challenge 6 - Heads I Win, Tails You Lose

phplogo.jpg

This challenge tests your understanding of generating random numbers and testing using the IF-ELSE statement.

You need to generate a random number between 1 and 2.

If the random number is 1 then echo "Heads, I win!".

If the random number is 2 then echo "Tails, you win!".

EXTENSION

Use a loop to generate the above 100 times.

Keep score of how many heads and tails there were and then echo out the result as something like this:

There were 48 heads and 52 tails.

(obviously the numbers will be generated by the script!)

EXTENSION 2

Can you think of a way of using an array with the contents as:

 

and using array functions to produce a similar result?