Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Introducing JavaScript Finishing the Game Wrapping It Up

Nour El-din El-helw
Nour El-din El-helw
8,241 Points

Trying to improve the game we made

I tried to use the ideas to improve the game that the instructor gave us but i think i messed a lot of stuff up : 1- i tried to display lives but it still displayed score. 2- i tried to use the lives system but now when the player touches any object(except the platform of course) the game crashes. thx for ur answer advance

Steven Parker
Steven Parker
231,248 Points

You forgot to show your code. Please make a snapshot of your workspace and post the link to it here.

2 Answers

John Bastian Bolhano
John Bastian Bolhano
4,800 Points

Crashed is caused by line 79 in game.js, you had a spelling error you wrote cuurentLife it should be currentLife

if (currentLife === losingLife) {
    player.kill();
}

in line 124 and 125 you had this

text = game.add.text(16, 16, "SCORE: " + currentScore, { font: "bold 24px Arial", fill: "white" });
    text = game.add.text(200, 16, "LIVES: " + currentLife, { font: "bold 24px Arial", fill: "white" });

your variable text has two assignments one for SCORE and for LIVES, try making a variable for each like this then add it two the update function below

textScore = game.add.text(16, 16, "SCORE: " + currentScore, { font: "bold 24px Arial", fill: "white" });
textLives = game.add.text(200, 16, "LIVES: " + currentLife, { font: "bold 24px Arial", fill: "white" });

function update() {
    textScore.text = "SCORE: " + currentScore;
    textLives.text = `LIVES: ${currentLife}`;
}

in line 71 and 72 you had this code

  } else if (item.key === 'poison') {
     currentScore = currentLife - 1;

what happens here every time you grab the poison the currentScore is decreased by one and not the life try changing it to this

  } else if (item.key === 'poison') {
     currentLife = currentLife - 1;

if you try to collect all the coins and the star your score will 105 and the game won't do anything since you have set winningScore = 100; so in line 76 try doing this one

   if (currentScore >= winningScore) {

this will make the badge appear if the score is equal or greater than 100

Hope my solutions helps and enjoy learning :D

Nour El-din El-helw
Nour El-din El-helw
8,241 Points

Hey thx but why did u put currentLife after a dollar sign and between brackets like that ${currentLife}

John Bastian Bolhano
John Bastian Bolhano
4,800 Points

ah right, that is an ES6 syntax, you will learn that in future lessons, it is way more convenient writing it that way XD. it is basically just

textLives.text = "LIVES: " + currentLife ;