Use what you've learned about click handlers to make add to this Mario game!
Let's take a look at the variables that've been declared for us already. What HTML elements have been saved?
Taking a look at lines 13 through 58, notice that there's starter code for many click handlers to make this game work. Now we just need to fill in the blanks!
For problem 1, let me fill in the blank with with the correct variable to make it so that when the user clicks the "Jump" button, Mario jumps and the coin disappears.
Now your turn! For problem 2, fill in the blank with the correct variable to make it so that when the "Jump Down" button is pressed, Mario will jump down. Make sure you eraser the comment marks so you can test this code out on the actual web page!
Stop here!
For problem 3, I'm going to do a bit more and write the whole click handler, including the variable, .onclick
, and the keyword function
.
First, what variable should I fill in the blanks with so that when I click the "Change Color" button the background of the game changes color?
Then, what should I write in the other two blank?
4: For problem 4, fill in the blanks on line 41 with to make a click handler for the "End Game" button. This would change the text of the h1
to "Game Over" when the button is clicked.
5: For problem 5, fill in the blanks so that when the when the "Update Score" button is clicked, the counter score goes up to "1" instead of 0.
6 Now Try writing the WHOLE click handler! Write the code that would make Mario get bigger when the "Grow" button is clicked. Use .style
and give Mario a width
of 300px
.
Hint:
- What variable holds what you will be clicking? That should go on the first line.
- What variable holds what you change with
.style
? That will go on the second line.