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 Express Basics Parameters, Query Strings, and Modularizing Routes Adding Links

mulgey
mulgey
9,899 Points

Elementary question but i hope you ll help!

in the if statement,

" templateData.hint = hint "

how does it work? I translate it like = we add hint to templateData and store it in "hint",

instead, logic should be like this instead? = add hint to templateData and store it in "templateData",

Of course if i modify code like this, it doesn't work but i really need someone to tell me the logic behind this very simple line of code.

Thanks

2 Answers

Torben Korb
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Torben Korb
Front End Web Development Techdegree Graduate 91,433 Points

Hi mulgey. There is an object named templateData and we define a property called hint and assign the property what's inside the hint variable (that we assigned before from the card with the given ID).

Whatever property we define on the object is accessible with the dot notation, for example:

const hint = 'some string';
const obj = {};
obj.hint = hint;
console.log(obj.hint); // Logs out 'some string'
console.log(obj); // Logs out '{ hint: 'some string' }'

Hope this helps to answer your question. Good luck!

William Wei Luan Ting
William Wei Luan Ting
4,254 Points

Torben's example is really clear but let me take a stab at trying to put these into simple words.

templateData.hint = "hint" 

The way I look at this line is to break it down into three different parts, then realize it is just a way to organize data in a way that can be used later.

1st part is everything before the period "." or in this case templateData. This is where you can create a name or the data you want to store. You can name this just about anything you like. It's just a name so you can remember where the data will be later.

2nd part. now lets look at the .period and the word right after it or in this case .hint. This is a way to add a reference so we can use the data later.

3rd part is ="hint". the equal symbol is used here not like a math problem but as a way to assign a value and everything inside the quotes will be stored and you can call on this later using the names from part 1 and 2.

I like to compare this to notes inside a file cabinet. Where part one, everything before the period, is the name of the cabinet, and .hint is the label on the folder, and the third part is what is written on the note. And remember that the equals sign is used to assign value.