5.16 Exercise: Blog publishing Object

In this exercise, I want you to create a blog post object with these properties. title, body, author, views, which represents the number of times this post has been viewed. We have the Comments property, each comment should have some properties. Author and body. And finally, another property, that every post should have isLive. Now, this can be true or false. So, again, you need to use the object literal syntax to create and initialize a blog post. Give each property a value, the actual value doesn't really matter. I just want you to get familiar with the object literal syntax. Here's a solution. So let's create a post object, using the object literal syntax We set the title to a, the body to b, the author to c, so these three properties are strings. The views now have to be a number, we can set it to 10, the comments have to be an array because we can have multiple comments, so we set that to an array, now each comment has to have two properties, so each comment has to be an object . So again, we use object literal syntax to initialize a comment object. We set the author to a and the body to b. We can have another comment in this array. Let's duplicate that, with different values and finally we need to add the isLive property, so we set isLive to true. And then let's do a console.log of post, inspect this on the console, so we can see that the comments property is an array with two objects, now if we click that, you can see the properties of each object. We have an author and a body. That's it for this little exercise on blog publishing objects in JavaScript, we'll see you in a very next video.