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 trialRaymond Leong
Full Stack JavaScript Techdegree Student 211 PointsI keyed in everything as per the video instructions but everytime I collect the poison, +10 and +20 for coins
Hi, opened a new workspace thinking that something wasn't right initially when everytime I collect the poison, I have +10 points to my score and +20 points when I collected the coins.
I made sure all the codes are correct but it still happens. Anyone facing the same issues?
Trevor Osterman
4,016 PointsHaving the same issue -- all items are still granting +10 despite what I have written in my code:
// when the player collects an item on the screen function itemHandler(player, item) { item.kill(); if (item.key === 'coin') { currentScore = currentScore + 10; } else if (item.key === 'poison') { currentScore = currentScore - 25; } else if (item.key === 'star') { currentScore = currentScore + 25; } if (currentScore === winningScore) { createBadge(); } }
Only different in the code I've written to what's shown in the video is that my '+' and '-' are shown in red like the value, not in black, but I'm not sure that's what's causing the issue.
Steven Parker
231,275 PointsTrevor Osterman — try starting a fresh question and include a link to a workspace snapshot. That will make it possible to do a thorough analysis of your issue.
2 Answers
Austin Morphies
308 PointsHey Raymond, I'd make sure instead of copying and pasting the following code: currentScore = currentScore + 10; Make sure you Cut instead.
I made this mistake as well and copied instead of cutting and pasting. In the end your code should look something like this:
// when the player collects an item on the screen function itemHandler(player, item) { item.kill(); if (item.key === 'coin') { currentScore = currentScore + 10; } if (currentScore === winningScore) { createBadge(); } }
Steven Parker
231,275 PointsThe original code adds 10 points for any kind of item. This is the same in the video and the workspace.
In the video, you make some changes to handle the items differently based on what kind they are.
Raymond Leong
Full Stack JavaScript Techdegree Student 211 PointsRaymond Leong
Full Stack JavaScript Techdegree Student 211 PointsI have found the issue, apparently there's been an additional line of code of currentScore = currentScore +10 that is present at the bottom of the code that was originally there but wasn't present in the video. Perhaps a check is required?