Flash Coding – Heads or Tails

We were introduced to the task by learning a handful of useful programming definitions.

Instance Name: Are used to identify the on screen object.

Function: Is a method / action that performs a specific task using a collection of commands to return a value.

Event Driven Programming: This is a programming paradigm in which the system / method of the program is triggered by an event. These can include user clicks and in response the a key being press.

Variable: A variable is information which can be changed and stored, depending on conditions assigned to it. Examples of this include keep track of a score or even tracking of a health bar.

If Statement: Also know as a conditional statement. Can be used to ask a question, if proved to be true, then performs a function or displays information.  This can be progressed further with “Else” statements which if then proves the conditions are not true, it then displays alternate information or commands.

We were then tasked on creating a game of heads or tails using the terms we had just learnt. Firstly, creating a function called “flip”, which within it contained an “if” statement. This was combined with an extra function called math.random() which generated a random number between 0 and 1. From there, we built the conditional statement:

HeadsorTails2

The if “math.random() < 5” section means if the random number selected is less than 5 then perform the following action if true. Else, if the condition is not true (the number is greater than 5) then perform this alternative action. This represents the 50% chance of a coin toss landing heads or tails.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s