Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Build an Object Challenge, Part 1 Solution

huckleberry
huckleberry
14,636 Points

Build 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 ...

  1. create a script that creates a bunch of student records
  2. 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 - :sunglasses:

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
Ionut Costica
737 Points

Actually, 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.
huckleberry
huckleberry
14,636 Points

yeah 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 - :sleepy:

As long as we all notice it, we're not crazy.

Michael Eaton
Michael Eaton
5,131 Points

Also, you'll notice Dave doesn't quote the first objects number properties but does the rest, oversight I guess...

I 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?