Purpose: Java Scipt Based Slot Machine
This is a faily simple project using lessons we have learned from Example 2: The Pen and Paper RPG Generator. We need to generate 3 random numbers. For simplicity sake with will start generating numbers from 1-3. Unlike the RPG generator we will not need to store these numbers to recall them later. Once we have 3 numbers generated we will have to compare them with eacj other to see if they are the same number.
So how do we do that?
In our function we will create and if statement. What is an if statement. An if statement is simply telling the function if this happens do this. You cam have many different if statements within one function that have many different outcomes. See the example below.
if (a == b){ this block of code will run}; else if (a != b){this block of code will run }
in the above example the if statement is followed bed the condition statement. When looking at the if line we are asking the statement to evaluate if a is equal to b. On the else if line we are asking the code to evaluate if a is not equal to be. You can have as many if and else if statements that you want in a block of code.
Ok lets generate numbers and compare them.
The first thing we will do is generate 2 numbers and compare them with an if statement. We will also use an else statement to see if they are equal to each other. When we have an if statement with an else the program will try and equal all the if's and else if's if none of the conditions are met it will do the else statement.