Table of content
|Read No. | Name of chapter| |:———: |:————–:| |7|Domain modeling| |7|Tables| |7|Functions, Methodes, and objects|
# Domain Modeling
Domain modeling is the process of creating a conceptual model in code for a specific problem. A model describes the various entities, their attributes and behaviors, as well as the constraints that govern the problem domain. An entity that stores data in properties and encapsulates behaviors in methods is commonly referred to as an object-oriented model.
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.
|Property|Data|Type| |——–|—-|—–| |epicRating|1 to 10|Number| |hasAnimals|true or false|Boolean|
Here’s an implementation of the EpicFailVideo constructor function.
This is object-oriented programming in JavaScript at its most fundamental level.
1- The new keyword instantiates (i.e. creates) an object.
2- The constructor function initializes properties inside that object using the this variable.
3- The object is stored in a variable for later use.
Generate random numbers
To model the random nature of user behavior, you’ll need the help of a random number generator. Fortunately, the JavaScript standard library includes a Math.random() function for just this sort of occasion.
The function uses both Math.floor and Math.random to calculate and return a random integer between min and max.
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. To calculate the number of viewers per day, generate a random number between 10 and 30 and then multiply it by the epic rating of that video.
Tables
Basic Table Structure
-
< table >: The < table > element is used to create a table. The contents of the table are written out row by row.
-
< tr >: You indicate the start of each row using the opening < tr > tag. (The tr stands for table row.)
-
< td >: Each cell of a table is represented using a td > element. (The td stands for table data.)
Table heading
< th >
The < th > element is used just like the < td > element but its purpose is to represent the heading for either a column or a row. (The th stands for table heading.)
Spanning ColumnS
The colspan attribute can be used on a < th > or < td > element and indicates how many columns that cell should run across.
Spanning rows
The rowspan attribute can be used on a < th > or < td > element to indicate how many rows a cell should span down the table.
Long tables
There are three elements that help distinguish between the main content of the table and the first and last rows (which can contain different content). These elements help people who use screen readers and also allow you to style these sections in a different manner than the rest of the table (as you will see when you learn about CSS).
- < thead >: The headings of the table should sit inside the <thead> element.
- < tbody >: The body should sit inside the < tbody > element.
- < tfoot >: The footer belongs inside the < tfoot > element.