Objects in Action
Lets bring together everything we learned and find some task to implement in our live site example starting with Objects.
Video Transcript
00:00All right, that's all we have with our shortcuts.
00:02It's time for us to start practicing and seeing it
00:04actually in action.
00:05To do that, I'm going to move into our end final project.
00:09And in our end final project, I prepared in advance.
00:13Basically, I took one by one almost.
00:16I basically went into our source code.
00:18And I copied from our source code.
00:20And I, well, let me delete that because I did that
00:22while I was testing things out.
00:24Let me save that.
00:25So you'll see that in our class, right?
00:26You'll see the header with the JavaScript 101,
00:29learn basic coding, blah, blah, blah, blah, blah.
00:32And there's a call to action as well.
00:34If we look into our final JS in our index end.html project,
00:39we'll see that the final.js has now we created an object.
00:43It has three properties, that property of title
00:46with the shorthand way that we've just created.
00:49We have a summary.
00:50We have a CTA.
00:51By the way, notice that in our last one,
00:53we're not putting a comma because there aren't other
00:55properties after it.
00:56You only put a comma when there are more properties.
00:58Very similar to the way you would work with functions,
01:01only difference is that you're giving them a name key.
01:04A name, a key value, key value, key value.
01:07All right?
01:09So now that we have that object, let's
01:10see how do we actually switch the content.
01:13Now there's another couple of small stuff
01:15that I'm going to talk to you in a second
01:17right after we're done with this.
01:19So first of all, let's just get the title in.
01:22We'll get, and then we'll move on to the summary.
01:24And we'll talk more about that exception.
01:26To do that, I want to go to our project.
01:28There are smarter ways of doing it,
01:29but we're just going to use our get element by ID.
01:32To do that, I'm going to set up both for my title.
01:36I'm going to go into my title.
01:38And I'm going to call this main title.
01:42I'm going to go to my paragraph.
01:44I'm going to give it an ID of main summary.
01:51I'm going to go into our call to action button.
01:54And I'm going to give it an ID of main CTA.
02:01All right?
02:02Let me just make sure that I gave names that were similar.
02:04Yes, I did.
02:05Title, summary, CTA.
02:06And on the other end, I just called it main
02:09because we might have more than later on.
02:11And we want to make sure that we have a name that's
02:13very explicitly describing where we are right now.
02:17All right.
02:17So let's test this out.
02:18So first of all, I'm going to go to my document.
02:20I'm going to get element by ID.
02:22I'm going to start with my title, which
02:24was called main title.
02:26Now that I got my main title, the next step for me
02:28is I'm going to go into my inner HTML.
02:30And I'm just going to replace it.
02:32So I'm going to replace my inner HTML with that O title
02:35that we've just created.title.
02:37Now, if I go to the file and I watch it in a live site,
02:40so if I go to the design itself,
02:42we're going to see now that we're seeing JavaScript 103,
02:45even though in our original source code,
02:47it was JavaScript 101.
02:50And the reason is because in our JavaScript,
02:52we replaced it to be JavaScript 103.
02:54Now, the changes that we will do in the summary itself
02:57might not be as obvious or as clear.
03:00And really, the only reason is because we
03:02didn't change any copy inside, which we could.
03:04But for our sake of purpose, let's just
03:06trust that it works.
03:08Well, it will change just something small, just for summary,
03:13summary, main summary, main summary.
03:15And let's just change your learn the basic JavaScript skills
03:24needed from any site owner, although that doesn't really
03:27make any sense.
03:28It doesn't really matter.
03:29For our example, let's test it out,
03:31learn basic JavaScript skills, yada, yada, yada.
03:33We got it.
03:35Last but not least, the exact same thing.
03:37All that's left for us is to change the CTA itself.
03:40Now, obviously, in a real live example,
03:43we might want to have our CTA.
03:45And by the way, although we usually,
03:47and this is a small comment, usually we
03:48would only use lowercase for text.
03:51In this scenario, because I know
03:53that this is a bucket of text, CTA is an acronym.
03:57And as an acronym, usually acronyms come in all uppercase.
04:00You can make that decision of how you want
04:02to work when you're programming.
04:04Personally, that's my personal opinion
04:07when I'm building an object that I know this is a data
04:09bucket.
04:10It's not variables, functions.
04:12It's not classes.
04:13I know it's not.
04:15That's why I'm fine with that.
04:16But I know earlier we said that we
04:18want to stick to whatever convention we have.
04:20So if you decided that your convention is lowercase
04:24for variables no matter what, so make sure
04:27that you start with a lowercase no matter what
04:29and that it's all lowercase.
04:31In my scenario, I made an executive decision
04:34that I'm fine with it.
04:35And if you're fine with it as well, so do it as well.
04:37If not, then just do it all lowercase.
04:40And we'll see that our register now,
04:41let's just switch it up to something else.
04:44Let's do register later, which is something
04:46that a lot of people do anyways.
04:49That would probably be surprising for people
04:50if they would see register later on a site instead of register
04:53now.
04:54And if we go back to the design, we'll see register later
04:56instead of the register now that we had earlier.
