Mole UnEarther - Creating Video Games with Phaser.js

Hey Everyone.

I’m stuck on #8 in the Mole UnEarther project.

#8 instructions: Now that we have a function to update the timer, we can use it after each second elapses.

Locate the onSecondElapsed() function inside create() . This function is already set up to execute after every second passes. We can take advantage of this to also update the timer by making our call to the updateTimer() function inside the onSecondElapsed() function.

When we run the program again, we can see our timer count down!

My code:
create() {

let updateTimer = () => {

  variable -= 1;

}

// executed after every second passes

const onSecondElapsed = () => {

  if (isPaused === false) {

    console.log(updateTimer);

So, I added the updateTimer function , the variable -= 1, and the console.log(updateTimer); BUT …

The timer does not count down when I click save. Someone help please!

-Suzana

Hello, @webninja74987, and welcome to the forums.

The instructions: “We can take advantage of this to also update the timer by making our call to the updateTimer() function inside the onSecondElapsed() function.”

You don’t have a call to the updateTimer function in your onSecondElapsed function. console.log does not call functions. console.log is a function that prints the argument passed to it to the console. If you open your browser’s console, and play the game, you’ll see something like the following printed to the console every second:

function updateTimer()

You want to add a call to the updateTimer function rather than print the function.

Hint:

How do we call any function in JavaScript?

Answer:

We add () to the end of its name: myFunction()
If our function requires arguments, we include them between the ()'s: myFunction(arg1, arg2)

1 Like

Thank you.

I changed it to:

create() {

const updateTimer = () => {

  variable -= 1;

}

// executed after every second passes

const onSecondElapsed = () => {

  if (isPaused === false) {

     updateTimer()

   

    // display the new time to the user

    this.updateTimerText();

  }

Still not seeing the count down though. When I tried " function updateTimer()" the screen was blank. I’m gonna try “let updateTimer(-1)” and see what happens …