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 trialhuckleberry
14,636 PointsBuild an Object Challenge, part 1 Solution: Why does Dave place the numbers in quotes?
I'm curious as to why in the part 1 video where the challenge instructions were given by Dave McFarland it was stated that he wanted us to ...
- create a script that creates a bunch of student records
- then prints those records to a webpage
Steps:
create a data structure to hold information about a group of students
name the array students
this will hold a list of objects
each object will represent a student
each object will contain the following properties.
name
track
achievements - number value
points - number value
create at least 5 student objects
yet in the solution video he stored the data in achievements and points as strings.
Was there a reason for this or was this just an oversight? Am I missing something here? I know he covered JSON in the video before that and stated that object structures in JSON are all strings so did that have anything to do with why he entered them as strings?
Thanks!
Cheers,
Huck -
p.s. Here was my solution prior to the solution video. I thought he wanted us to go all the way and not just create the object first and then work on getting it printed to the page after the first solution vid.
4 Answers
Ionut Costica
737 PointsActually, in JSON number values are not put in quotes (the same with Boolean values). Easiest way to see how certain values would look like in JSON would be to run JSON.stringify()
on an object containing those types of values, i.e.:
JSON.stringify({a: 1, b: 'string', c: true});
```returns the string _'{"a":1,"b":"string","c":true}'_.
The string format of the values in the answer video is probably an oversight, given that the problem itself requires them to be numbers.
omgninjas
12,924 PointsAs long as we all notice it, we're not crazy.
Michael Eaton
5,131 PointsAlso, you'll notice Dave doesn't quote the first objects number properties but does the rest, oversight I guess...
seattler
2,067 PointsI have the very same question! I noticed that in the solution portion of video part 1. Dave doesn't use quotations for his 1st object's properties: achievements and points. Yet for the rest of the objects he uses quotations. see below:
{ name: "Dave", track: "Front-End Web Development", achievements: 158, points: 14730 }
// achievements and points have no quotations. Yet the next 4 objects do use quotations. Like below:
{ name: "Jody", track: "i0S...", achievements: "175", points: "16375"}
// See achievements and points now have quotations. Is the consensus that this was a mistake?
huckleberry
14,636 Pointshuckleberry
14,636 Pointsyeah yeah I understood that JSON numeric values aren't actually put in quotes but since I had only just watched the video about JSON about 20 min before the challenge video and then I got to the solution video, I saw him putting them in quotes and I was like "wait... what? crap... he said something about JSON being being one big string so... does this have something to do with that? did I miss something? bah... it's 2am I'll just ask on the forums"
Thanks though, I agree -- probably just an oversight but, had to make sure since I'm so... zzzzzzzzzzzzzzzzzzz
Cheers,
Huck -