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 trialcyber voyager
8,859 PointsWell, that's weird.
Hello, as I was watching this video I saw this:
classroom.set('stevenJ', 'stevenJ');
Why is he using the same value on the set()? I am a bit confused about this. If someone would like to clear things up for me I would be very grateful.
Thank you very much. Stavros
cyber voyager
8,859 PointsNo worries Caleb, thank you for taking your time to comment :)
Andrew Gursky
12,576 PointsHaven't taken that particular course, so I don't know context. Best of luck though!
cyber voyager
8,859 PointsThank you Andrew :)
2 Answers
Pavel Trofimov
12,535 PointsUnless I'm looking at a different part of the video, he's using
classroom.set('stevenJ', stevenJ);
The second parameter is without quotes. So I think what's happening is he's setting the key name first (that's "stevenJ"), and then the value (which is the object assigned to the variable stevenJ).
Osama Awan
Courses Plus Student 8,676 Pointswell there is nothing wrong or wired doing this classroom.set('stevenJ', 'stevenJ');
. You can set the key same as it's value. so getting the value will result in classroom.get('stevenJ');
stevenJ, or what else you can do is.
let stevenJ = "anyname";
classroom.set('stevenJ', stevenJ);
Now the key will be 'stevenJ' and it's value will be anything inside that stevenJ variable.
Caleb Kleveter
Treehouse Moderator 37,862 PointsCaleb Kleveter
Treehouse Moderator 37,862 PointsSorry Stavros. I am not very fluent in JS currently, so I am not sure why this was done. I hope you find an answer!