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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Gavin Lefleur](https://secure.gravatar.com/avatar/86d56620c486b5bbbd154b52945e89e8?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Gavin Lefleur
Full Stack JavaScript Techdegree Student 742 PointsHelp - TypeError for challenge 1 (Full stack Tech Degree - JS)
Hi Guys,
I am getting a 'Type error' using let command for one of the challenges in JS. Can anyone explain to me why?
let points = 100;
let bonusPts = 50;
let points += bonusPts;
console.log(points);
2 Answers
![jb30](https://secure.gravatar.com/avatar/681668d7cc4c5486851384a0feddda37?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
jb30
44,806 PointsYou can't redeclare values with let
in Javascript. let points += bonusPts;
should be points += bonusPts;
.
![Gavin Lefleur](https://secure.gravatar.com/avatar/86d56620c486b5bbbd154b52945e89e8?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Gavin Lefleur
Full Stack JavaScript Techdegree Student 742 PointsHi jb30
I am still confused ... could you please break this down if you have a moment Regards
G
![jb30](https://secure.gravatar.com/avatar/681668d7cc4c5486851384a0feddda37?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
jb30
44,806 PointsThe line let points += bonusPts;
gives a syntax error. It is the short form of let points = points + bonusPts;
, which requires points
to already have a value on the right side and using it to compute the value for points
on the left side. Since let
is used to declare a variable for the first time, I would expect there to be a syntax error when you try to declare it using its own value, since if it already has a value, you have already declared the variable.
While all of my browsers agree that using let
with +=
is a syntax error, they disagree on whether let points = points + bonusPts;
is also a syntax error. If you don't know what browser your code will be run in, relying on redeclaration of your variables using let
could be an issue.
Gavin Lefleur
Full Stack JavaScript Techdegree Student 742 PointsGavin Lefleur
Full Stack JavaScript Techdegree Student 742 PointsThe original code and question is below:
Evaluate the code in app.js. The code currently produces a TypeError. Adjust the code so that the points variable holds the expected value.
const points = 100; const bonusPts = 50;
points += bonusPts; console.log(points);