Let's write out an if-else statement that checks the amount of money in a character's pocket, returning different debug logs for three different cases: greater than 50, less than 15, and anything else:
- Open up LearningCurve and add a new int variable, named currentGold. Set its value to between 1 and 100.
- Declare an if statement to check whether currentGold is greater than 50, and print a message to the console if this is true.
- Add an else-if statement to check whether currentGold is less than 15 with a different debug log.
- Add an else statement with no condition and a final default log.
- Save the file and click on Play:
With currentGold set to 32 in my example, we can break down the code sequence as follows:
- The if statement and debug log is skipped because currentGold is not greater than 50.
- The else-if statement and debug log is also skipped because currentGold is not less...