Reading-notes

Object-Oriented Programming, HTML Tables”

Domain Modeling

Define a constructor and initialize properties

To define the same properties between many objects, you’ll want to use a constructor function. Below is a table that summarizes a JavaScript representation of an EpicFailVideo object.

Generate random numbers :

EpicFailVideo.prototype.generateRandom = function(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }

console.log(parkourFail.generateRandom(1, 5)); console.log(corgiFail.generateRandom(1, 5));

### As you can see, methods can be added to a constructor function’s prototype. Think of the prototype as an object’s stunt double. Whenever a scene is too dangerous, you can substitute in the prototype to do the work while the object takes all the glory. More on how that works below.

## Calculate daily Likes :

+Popularity of a video is measured in Likes. And the formula for calculating Likes is the number of viewers times the percentage of viewers who’ll Like a video. In other words, viewers times percentage.

A table represents information in a grid format. Examples of tables include financial reports, TV schedules, and sports results.

Basic Table Structure:

Table Headings:<tH>:

Long Tables:

Spanning Rows:

You may also need entries in a table to stretch down across more than one row. The rowspan attribute can be used on a < th> or < td> element to indicate how many rows a cell should span down the table.

WHAT IS AN OBJECT?

IN AN OBJECT: VARIABLES BECOME

KNOWN AS PROPERTIES If a variable is part of an object, it is called a property. Properties tell us about the object, such as the name of a hotel or the number of rooms it has. Each individual hotel might have a different name and a different number of rooms.

IN AN OBJECT: FUNCTIONS BECOME KNOWN AS METHODS If a function is part of an object, it is called a method. Methods represent tasks that are associated with the object. For example, you can check how many rooms are available by subtracting the number of booked rooms from the total number of rooms.

EX This object represents a hotel. It has five properties and one method.The object is in curly braces. It is stored in a variable called hotel .

CREATING· OBJECTS USING LITERAL NOTATION:

CREATING OBJECTS USING CONSTRUCTOR SYNTAX :

Once it has been created, three properties and a method are then assigned to the object. (If the object already had any of these properties, this would overwrite the values in those properties.) To access a property of this object, you can use dot notation, just as you can with any object. For example, to get the hotel’s name you could use: hotel .name Similarly, to use the method, you can use the object name followed by the method name: hotel.checkAvailability(1,2,3)

ADDING AND REMOVING PROPERTIES:

Once you have created an object (using literal or constructor notation), you can add new properties to it. You do this using the dot notation that you saw for adding properties to objects on pl03. In this example, you can see that an instance of the hotel object is created using an object literal. Immediately after this, the hotel object is given two extra properties that show the facilities (whether or not it has a gym and/or a pool). These properties are given values that are Booleans (true or false). Having added these properties to the object, you can access them just like any of the objects other properties. Here, they update the value of the cl ass attribute on their respective elements to show either a check mark or a cross mark. To delete a property, you use the keyword delete, and then use dot notation to identify the property or method you want to remove from the object. In this case, the booked property is removed from the object.

WHAT ARE BUILT-IN OBJECTS?

Browsers come with a set of built-in objects that represent things like the browser window and the current web page shown in that window. These built-in objects act like a toolkit for creating interactive web pages. The objects you create will usually be specifically written to suit your needs. They model the data used within, or contain functionality needed by, your script. Whereas, the built-in objects contain functionality.

GLOBAL OBJECTS:

summary :