reading-notes

View on GitHub

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.

code

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.

code1

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.

code2

Tables

Basic Table Structure

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).

Functions, Methods, and Objects

creating an object: Constructor notation

The new keyword and the object constructor create a blank object. You can the add properties and methods to the object.

constructor notation

Creating many objects: constructor notation

Sometime you will want several objects to represent similar things. Object constructors can use a function as a template for creating objects.

several objects

reating an instance of the date object

In order to work with dates, you creat an instance of the Date object. Y can then specify the time and date you want it to represent.

Date