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.

link:
https://www.codecademy.com/paths/create-video-games-with-phaser/tracks/game-dev-learn-javascript-function-and-scope/modules/game-dev-project-functions-and-scope/projects/mole-unearther

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', 'https://codecademy-content.s3.amazonaws.com/courses/learn-phaser/mole-unearther/background.png');
	// 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
	this.load.spritesheet('mole',
		'https://codecademy-content.s3.amazonaws.com/courses/learn-phaser/mole-unearther/mole-sprite.png',
		{ frameWidth: 198, frameHeight: 250 });
}

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


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

			// display the new time to the user
			this.updateTimerText();
		}
	};

	// display background
	this.initializeBackground();

	// set up score text
	this.initializeScoreText();

	// go through each burrow and set up key listeners on the corresponding key
	this.initializeBurrowKeys();

	// set up animation callbacks
	this.initializeAnimations();

	// set up mole and place in first location
	this.initializeMole();

	// set up text for timer and callback for countdown
	this.initializeTimer(onSecondElapsed);
}

// periodically checks and handles user input by updating game logic
update() {
	if (timeLeft <= 0) {
		// Provided for user
		this.scene.stop('GameScene');
		this.scene.start('EndScene');
	}

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

		this.displayRewardText();

		// display the new score to the user
		this.updateScoreText();
	};

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

  
  
		this.displayPenaltyText();

		// display the new score to the user
		this.updateScoreText();
	};

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

onBurrowHit(‘j’)
} else if (Phaser.Input.Keyboard.JustDown(gameState.kKey)) {
onBurrowHit(‘k’)
} else if (Phaser.Input.Keyboard.JustDown(gameState.lKey)) {
onBurrowHit(‘l’)
}
}

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
      this.updateTimerText();
    }
  };

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.