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 Foundations Variables Scope

why is answer b incorrect in question 5 of 5 in the section /variables/scope#

answer b the 5th question for the lesson /variables/scope# seems to be "treehouse", it appears to be within the scope of function bam; var part 2 "treehouse". console.log(part2) appears to call the value "treehouse".

Hugo Paz
Hugo Paz
15,622 Points

Hi Eddie,

The order of the questions change every time you do the quiz. Could you post the full question please?

1 Answer

I assume this is the question you are talking about?

var part1 = "Team ";

function bam() {
    var part2 = "Treehouse";
}

bam();

console.log(part2);

The answer is Reference Error : Part 2 is not defined. The variable part 2 is only available in the scope of function bam. The part2 variable is not global so when you try to print you get the value of undefined(since part2 is local to the function).

Hope that helps.