Coding skills you will learn in Episode 2
If/Else or Conditional Statements
Conditional statements or if/else statements are instructions you want the code to execute when certain conditions are met. For example, you can use a conditional statement to help you decide what to wear based on the weather. If it is sunny outside (condition #1), then I will wear my sunglasses (an action I want to take). Else (any other weather - condition #2), I will not wear my sunglasses. You first will encounter an if/else statement for the first time when changing the spawn rates of an enemy (see image above).
Some functions return a value. That means that the function will give you a new value. Think of it like chopping onions. There is no "new" product, just the same product in a new format. You first will encounter an if/else statement for the first time when changing the spawn rates of an enemy (see image above).
The layout of a function
1. Function name
2a. Indicates the beginning (or opening) of the function.
2b. Indicates the end (or closing) of the function.
Everything between three and 2b is an if/else statement. You will be making your changes to the code between number three and 2b.
Adding Two Enemies in a Function
This challenge is a tough one. Your solution will rely on what you’ve learned in the previous challenges.
Hint #1: If you want to display an enemy, you should return the name of the enemy. For example, return ‘squid’. It’s important that the name of the enemy type is surrounded in quotation marks.
Hint #2: You will need to use the random function in your code, so it will randomly select an enemy.
Hint #3: If you get stuck on a challenge, pay close attention to Saniel’s hints.