How to Create Variables for MicroWorld EX Projects - dummies

How to Create Variables for MicroWorld EX Projects

Some of your MicroWorld EX projects will need variables to help you count things. In this example, a Happy Birthday simulation needs a way to show whether a newborn baby is a boy or a girl. It also needs a way to count how many total boys and how many girls are born in a large population. Variables will be used for all three of these.

Variables are quantities that can have different values at different times. You will probably first learn about variables in a pre-algebra course. Math often uses single letters like a or x for a variable — and sometimes coding does, too — but coding also uses a whole word like “gender” or “boys” or “girls” for a variable name.

Create a variable as follows:

1. From the toolbar, click the Create a Text Box button; move into the workspace and draw a rectangle for the text box.

Now, instead of showing a title, this text box will be used to show the value of a variable.

2. Right-click (Windows) or Ctrl-click (Mac) inside the text box and select Edit from the pop-up menu.

3. Name the text box gender. The Show Name and Visible check boxes should be selected.

This text box will be used to show a discrete variable value — a value that can only be a certain number such as 0 (for a girl) or 1 (for a boy). Like flipping a coin, there is no “in-between” value — it’s either heads or tails, boy or girl.

Text boxes used as variables must remain opaque for the variable values to change.

4. Repeat Steps 1–3 to make two more text boxes to show variable values; name one girls and the other boys.

These will be counting variables or counters that count the total number of girls and the total number of boys. (Counting variable is not a formal mathematical term, just a description of how this variable is functioning in your program.)

To create a new text box with the same size and shape as an existing text box: Right-click (Windows) or Ctrl-click (Mac) inside the text box you want to duplicate and select Copy Box from the pop-up menu. Then right-click (Windows) or Ctrl-click (Mac) in the workspace and select Paste from the pop-up menu. A duplicate text box appears.

5. Drag the text boxes to where you want them positioned.

Your workspace should look similar to the example.