Transcript from the "Declaring & Assigning a Variable" Lesson
>> TODO 2, we're gonna declare and assign a variable called fact that's going to be an object that represents a statement, an answer that's true or false, and an explanation. The one that I had in here looked something like a statement of 1 plus 1 equals equals equals 2.
[00:00:25] The answer of true, I can't remember which version we're looking at if it's the text or the numbers. And then the explanation of what the plus operator does to strings, I think it was. So, hopefully you all chose totally different facts. Can somebody walk me through what they did for their statement object?
[00:00:49] So let's start with, we're gonna assign a variable and again, this statement now. In this case, the statement is just gonna be, sorry, the fact is just gonna be one fact for this page, so we're not gonna change it. It's just gonna be this page, your page always has one fact.
[00:01:07] In my page's case, it was always the fact string 1 + string 1 === string 2. And so, if we look at my solution, hopefully, no spoilers, let's see. We saw that what I did, scrolling down, was something like this. Ignore that, something like this, okay? So a fact, I have statement, and so an explanation.
[00:01:42] Now, let's look at what you all did. So who can walk me through their solution? OJ, did you wanna share?
>> Sure I did, I tried to do const fact equals and then I do the squiggly lines.
>> Curly braces, yep
>> Squiggly braces statement, colon,
>> Statement, colon.
>> Arrays are just like objects.
>> Arrays are just like objects, love it, okay?
>> Comma, answers, colon, an array, yes, no.
>> Interesting, okay. So in this case, what we want, we're gonna have two options here. In fact, where in this case, we're not gonna change the options from true false.
[00:02:17] So we're just gonna keep all of our questions like true/false questions. And we already have buttons set up to say true and false. So could we edit those to say yes or no instead? Absolutely, we could. In this case, what we wanna do is represent, for this particular fact, what is the correct answer?
[00:02:35] So in this case we probably just want answer singular, and in this case it could be false, or I mean depends what you, this is a philosophical question here. Let's say, maybe we move this arrays are just objects, we'll maybe make it a little trickier. But arrays are like objects in that they actually are objects with some special properties, then our answer would probably be true.
[00:03:07] Okay, so now the value of your answer here, you could have had two options. You could have had the boolean value true or false as a boolean value. Or you could also have a string value of the word true or the word false. Both are valid. Later, we're gonna have to deal with the fact that we may have had a choice of whether to put a boolean here or a string.
[00:03:38] And so, both are valid, we're gonna have to be conscious of the fact that answer is a boolean here, if we used the boolean, yeah?
>> And then explanation, colon, changed my mind.
>> [LAUGH] Okay, so in this case, changed my mind could be, it's your page, you can put whatever you want.
[00:03:58] But maybe we could say something like to explain in a little bit more detail why the answer is true. So we could say like arrays are a kind of object or something like that. Or arrays are type object or whatever it is, right? So depending on what your fact is, you get to decide what this explanation is, yeah?
[00:04:27] Okay, so I'm just gonna say arrays are kind of object with special properties. And are we done? Yes, question.
>> Okay, so when you showed us the one that you did, all of the IDs, the keys there, were in quote.
>> Quotes, that is a very astute observation.
[00:04:50] So, when we're looking at the coding here, and it's really difficult to read inside the inspector here. Which is why we appreciate syntax highlighting and IDEs and how they space everything out nicely. But you may have noticed that there were some quotes around the property names. And in fact, let's go back to our new tab.
[00:07:27] Because we're expecting something else there. However, I can still use the brackets notation to say my longer property and still get out the value. So, great question and revealed a little hidden trick that properties can do. And so, I think what's happening here is in the browser, how it's displaying it, it's just kind of indicating the stringiness of those property names for us, even though those quotes don't exist in my actual source code.