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

Chris Huynh
seal-mask
.a{fill-rule:evenodd;}techdegree
Chris Huynh
Full Stack JavaScript Techdegree Student 1,399 Points

Evaluate the code in app.js. The code currently produces a TypeError. Adjust the code so that the points variable holds

.....the expected value.

JavaScript Basics Challenge Task 1 of 1: Update the Value of a Variable.

Having trouble with the code, I've tried multiple times, don't know what to do, here's the code I wrote.

const points = 100; bonusPts = 50;

let points += 100; points = 50; console.log(points);

10 Answers

Steven Parker
Steven Parker
231,141 Points

Congratulations on resolving your own issue. :+1:
As you discovered, a variable declared as "const" cannot be changed later in the code.

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);

somebody help I can't figure the answer

Steven Parker
Steven Parker
231,141 Points

The statement "points += bonusPts;" would change "points" by adding the value of "bonusPts". But since "points" was declared as "const" it causes an error. Just declare "points" with "let" or "var" instead to allow it to be changed.

Steven Parker
Steven Parker
231,141 Points

That would also cause errors. In particular, "lets" should be "let" at the beginning, then remove the second "let" entirely. Note that even with the errors fixed, this code also has a very different functionality than the original.

Bujmaa Javzmaa
Bujmaa Javzmaa
165 Points

Change const to LET (all of them) then it works. The lesson I learned here is we can not use Const more than one time

Steven Parker
Steven Parker
231,141 Points

And even when you only use it one time, you cannot assign another value to that variable later!

Adam Gheli
Adam Gheli
2,091 Points

I'm still not able to figure this out. Not sure what I'm doing wrong.

Joan Bandoles
PLUS
Joan Bandoles
Courses Plus Student 435 Points

let points = 100; var bonusPts = 50;

points += bonusPts; console.log(points);

my answer:

var points = 0; points += 100;

var bonusPts = 50; var finalpoints = points + bonusPts; console.log(finalpoints);

I just changed all the conts to let and it worked for me :)

Isaiah Gadson
Isaiah Gadson
6,398 Points

what is the answer because it is hard?