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 JavaScript Numbers The Math Object Perform Operations With the Math Object

Nataly Diem
Nataly Diem
9,701 Points

Primitive numbers question

Hello, I was reading the article about Primitives that Guil linked in the Teacher's Notes. I have a doubt that I can't solve regarding to the second example:

// The Primitive let foo = 5;

// Defining a function that should change the Primitive value function addTwo(num) { num += 2; } // Another function trying to do the same thing function addTwo_v2(foo) { foo += 2; }

// Calling our first function while passing our Primitive as an argument addTwo(foo); // Getting the current Primitive value console.log(foo); // 5

// Trying again with our second function... addTwo_v2(foo); console.log(foo); // 5

How we can show the value "7" to the console log? I have tried adding a variable: let numberSeven = addTwo(foo) and then console logging it but I can't make it work.

Thank you.

1 Answer

Steven Parker
Steven Parker
231,248 Points

The "addTwo" function shown here performs addition, but doesn't do anything with the result. To pass the result back, add a "return num;" statement to the function.

For future questions, use Markdown formatting to preserve the code's appaearance.

Nataly Diem
Nataly Diem
9,701 Points

Thank you very much for the answer and the tip :)