Coding skills you will learn in Episode 2

In episode two, we introduce Javascript concepts such as variables, functions, arrays, and if statements. These concepts can be overwhelming, but the HACK team is here to help. Here are some useful definitions.


Variables

Variables in Javascript are like boxes that hold things. You give them names, just like labeling a box of Pokémon cards, so you can find it quickly. Use good names, so you know exactly what’s inside — like ‘Ultimate Pokémon Deck’. You will be asked to change variables for your first challenge.


 

Functions

Functions are like cooking recipes or the instructions that come with a LEGO set. Running a function goes through each of the steps until it reaches the end or is told to stop — like when we call you down for breakfast! You’ll be asked to update a JavaScript function when changing the spawn rate of an enemy.



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).


Return

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.

3. Comments

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.