Activity 3 - Declare your variables
Activity 3
This activity is split into 2 parts and will test your knowledge about variables. Before starting, look out for HINT (ACTIVITY 3)
in the code, where we declare a variable called lives
which stores the number of lives the player has, and use the variable to print out how many lives the player has at the start of the game. This should give you an idea for how to complete the following two parts.
Activity 3.1
At the start of the game, we should tell the player how many letters the word to guess has. For example, if the word to guess is "Hello"
, we should tell the player: The word has 5 letters
. If the word to guess is "Foundation"
, we should tell the player: The word has 10 letters
. We have already stored the number of letters in the numberOfLetters
variable, so use it to complete this activity.
To check if you have completed this activity correctly, press run, and make sure you see The word has 5 letters
(or some number other than 5) in the console.
Activity 3.2
There are two more pieces of information that we need the computer to store:
- The number of letters that the player has guess correctly so far.
- Whether or not the player won the game.
We will declare two variables to represent these pieces of information. Press run to make sure no errors appear in the console. Remember that variables do not produce console output, so for this part, we are only checking for the absence of errors.