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 trialChris Corpuz
401 Pointschanged sprite to mikethefrog and added life counter, but score stays at 0 doesn't change. help
that is my 1st snapshot of my workspace.. i would like to know what i need to add or did wrong as i'm very interested in learning the basics and more to become a future web developer
3 Answers
KRIS NIKOLAISEN
54,971 PointsBoth your Score and Life text elements are named text. So in the code you are setting the Life value to the Score value then immediately change it to the Life value, if that makes sense. Anyways the code I modified is as follows:
(1) Add another text variable at line 10. This will be text1 for Life.
var text;
var text1;
(2) Change text to text1 on line 129 for Life where both texts are created
text = game.add.text(16, 16, "SCORE: " + currentScore, { font: "bold 24px Arial", fill: "white" });
text1 = game.add.text(500, 16, "LIFE: " + currentLife, { font: "bold 24px Arial", fill: "white" });
(3) Change text to text1 on line 139 for Life where the value is set
text.text = "SCORE: " + currentScore;
text1.text = "LIFE: " + currentLife;
Here is a snapshot with the modifications and functioning score;
Gabriel Plackey
11,064 PointsI would look at exactly what you just changed when you did your last save. I can't find exactly what is wrong, but JS is not my best. Retrace your steps one by one and redo your last changes one by one as well and see exactly what is throwing it off. One problem I did notice is that you have currentScore when you need currentLife in one spot.
ARCHIT RANA
Full Stack JavaScript Techdegree Graduate 27,853 PointsSharing my solution for mikethefrog and life counter challenge:
Chris Corpuz
401 PointsChris Corpuz
401 Pointsthank you very much Kris! it now works flawlessly. now I am left with creating "game over" when you collect all 3 poisons.