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

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

okay so i finally found the answer. it was swapping out the const with lets to allow the code run.

10 Answers

Steven Parker
Steven Parker
243,266 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
243,266 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.

Try

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

Steven Parker
Steven Parker
243,266 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.

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
243,266 Points

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

Var points = 100; Var bonusPts = 50;

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

Hi guys,

this is the answer

const points = 100; let bonusPts = 50;

points.bonusPts; console.log(points);

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

Just change all const to let statement

const points = 100; --> let points = 100;

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

what is the answer because it is hard?