Functions and scope

so im making a moll smacking game but I don’t know whats wrong please can you tell me my mestake im pretty sure its somewhere in between 106 and 112.

thank you.


Hey @net0972535260, welcome to the forums!

Could you send your code please? Each exercise link is not unique for each person so we view our own code when we click on the link…

I think the error is somewhere in here

let timeLeft = 30

let score = 0

let isPaused = false

// Stores the current “key” location of the mole

let currentBurrowKey;

const gameState = {};

class GameScene extends Phaser.Scene {
constructor() {
super({ key: ‘GameScene’ });

	// list of all burrow locations
	// each location contains a corresponding key on the keyboard,
	// and the x and y pixel coordinates on the screen
	this.burrowLocations = [{
		key: 'j',
		x: 100,
		y: 310,
		key: 'k',
		x: 240,
		y: 390,
		key: 'l',
		x: 380,
		y: 310,

// import all of the visual assets we will use throughout the game
preload() {
	// calls the image function to load in the background, and assigns the image to the field key
	// the background is loaded from the given url
	this.load.image('background', '');
	// calls the spritesheet function to load in the mole as a spritesheet to make animations, and assigns it to the mole key
	// the mole is loaded from the given url with the given width and height
		{ frameWidth: 198, frameHeight: 250 });

// set up scene visuals, animations, and game logic when events occur
function updateTimer(){
  timeLeft -= 1;

	const onSecondElapsed = () => {
		if (isPaused === false) {

			// display the new time to the user

	// display background

	// set up score text

	// go through each burrow and set up key listeners on the corresponding key

	// set up animation callbacks

	// set up mole and place in first location

	// set up text for timer and callback for countdown

// periodically checks and handles user input by updating game logic
update() {
	if (timeLeft <= 0) {
		// Provided for user

	// user successfully hit the mole, so reward the user with 5pts
	const applyHitReward = () => {


		// display the new score to the user

	// user missed the mole, so penalize the user by taking away 5pts
	const applyMissPenalty = () => {
  function onBurrowHit (key) {
    if (key === currentBurrowKey) {
    } else {


		// display the new score to the user

	if (isPaused === false) {
		if (Phaser.Input.Keyboard.JustDown(gameState.jKey)) {

} else if (Phaser.Input.Keyboard.JustDown(gameState.kKey)) {
} else if (Phaser.Input.Keyboard.JustDown(gameState.lKey)) {

Could you please format your code?

Also, what is the error message? All programmers rely on error messages to figure out what’s wrong.

it doesn’t give an error message

I’m confused. I thought you said that there was an error.

This looks like Step 8 on the progress meter. Is that where you are in the game plan?

  const onSecondElapsed = () => {
    updateTimer()  // <- remove from here
    if (isPaused === false) {
      // -> insert here
      // display the new time to the user

At this point we should be able to Save, click, and watch the timer count down. The bonus is we get to see a mole peek out from a random hole.