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 One Solution

Crystal Vesely
Crystal Vesely
15,071 Points

Country Capital returns undefined

I coded this exactly like the video. However, the capital data is an array within the object. I attempted to put the bracket index at the end, example; 'country.captial[0]'. But it throws an error. When I remove the bracket index, it shows that the capital is undefined. In the video solution, there is no bracket index, but it shows the capital. Am I missing something?

Crystal Vesely
Crystal Vesely
15,071 Points

Also, could anyone explain to me how we were able to create a variable "countryHTML" without using const, let, or var?

Steven Parker
Steven Parker
243,318 Points

We can probably help if we can see your code. This video on Previews and Snapshots will show you how to make a snapshot of your workspace and then you can include a link to it here.

1 Answer

Steven Parker
Steven Parker
243,318 Points

The issue is simply a typo on line 35 of app.js:

              <p>${country.captial}</p>  <!-- original, "capital" misspelled as "captial" -->
              <p>${country.capital}</p>  <!-- corrected -->

Now it will work with or without the indexing. Leaving off the index causes the entire array to be listed, but since the array always contains just a single item there is no visible difference.

And for the other question: when JavaScript is not in strict mode (which it is not by default), assignment to an undeclared variable is allowed and implicitly creates a property on the global scope.