From 45fc90851265b481dc781104ab127e9eb5a9464e Mon Sep 17 00:00:00 2001 From: Patrice Thomas Date: Wed, 4 Jul 2018 19:14:38 -0400 Subject: [PATCH 1/5] added and populated JS file with objects,and stored results for objects in an array --- index.html | 0 main.css | 0 object-literals.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++ sales.html | 17 ++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 index.html create mode 100644 main.css create mode 100644 object-literals.js create mode 100644 sales.html diff --git a/index.html b/index.html new file mode 100644 index 0000000..e69de29 diff --git a/main.css b/main.css new file mode 100644 index 0000000..e69de29 diff --git a/object-literals.js b/object-literals.js new file mode 100644 index 0000000..3b27707 --- /dev/null +++ b/object-literals.js @@ -0,0 +1,56 @@ +//creating an object and giving it properties, methods + +let cookieShop1 = { + location: 'Bethesda', + Average_Cookies_Per_Customer:2, + min_Number_Of_Customers : 2, + max_Number_Of_Customers : 12, + Random_Number_of_customers : function () { + return Math.floor(Math.random () * (this.max_Number_Of_Customers - this.min_Number_Of_Customers +1 ) + this.min_Number_Of_Customers) + }, + Average_Cookies_Sold_Per_Hour: this.Random_Number_of_customers * this.Average_Cookies_Per_Customer, +}; +//creating an object and giving it properties, methods +let cookieShop2 = { + location: 'Rockiville', + Average_Cookies_Per_Customer:2, + min_Number_Of_Customers : 4, + max_Number_Of_Customers : 22, + Avg_CookiesSale : function () { + return Math.floor(Math.random () * (this.max_Number_Of_Customers - this.min_Number_Of_Customers +1 ) + this.min_Number_Of_Customers) + }, + Average_Cookies_Sold_Per_Hour: this.Random_Number_of_customers * this.Average_Cookies_Per_Customer, + +}; + +//creating an object and giving it properties, methods +let cookieShop3 = { + location: 'Washington DC', + average_Cookies_Per_Customer:2, + min_Number_Of_Customers : 6, + max_Number_Of_Customers : 110, + Avg_CookiesSale : function () { + return Math.floor(Math.random () * (this.max_Number_Of_Customers - this.min_Number_Of_Customers +1 ) + this.min_Number_Of_Customers) + }, + Average_Cookies_Sold_Per_Hour: this.Random_Number_of_customers * this.Average_Cookies_Per_Customer, + +}; + +//storing the result for each location in an array +let cookie_Sale_Per_Store = [cookieShop1, cookieShop2, cookieShop3]; +for (let i=0; i + + + + + Page Title + + + + + + + + + + + \ No newline at end of file From c4c2fccab73eeab694150db45cfb0e3483ff0c7f Mon Sep 17 00:00:00 2001 From: Patrice Thomas Date: Thu, 5 Jul 2018 17:46:36 -0400 Subject: [PATCH 2/5] pushing assignment to Git --- object-literals.js | 11 ++++++----- sales.html | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/object-literals.js b/object-literals.js index 3b27707..1f053d5 100644 --- a/object-literals.js +++ b/object-literals.js @@ -46,11 +46,12 @@ for (let i=0; i + -
    +
      From efda1bfad01ff7c94b0198754a1d13cdca6d6138 Mon Sep 17 00:00:00 2001 From: Patrice Thomas Date: Thu, 5 Jul 2018 21:13:09 -0400 Subject: [PATCH 3/5] creating Object Constructors --- Day2-Object-Constructor/README.md | 2 + Day2-Object-Constructor/index.html | 0 Day2-Object-Constructor/main.css | 0 Day2-Object-Constructor/object-constructor.js | 86 +++++++++++++++++++ Day2-Object-Constructor/sales.html | 17 ++++ object-literals.js | 26 +++++- 6 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 Day2-Object-Constructor/README.md create mode 100644 Day2-Object-Constructor/index.html create mode 100644 Day2-Object-Constructor/main.css create mode 100644 Day2-Object-Constructor/object-constructor.js create mode 100644 Day2-Object-Constructor/sales.html diff --git a/Day2-Object-Constructor/README.md b/Day2-Object-Constructor/README.md new file mode 100644 index 0000000..553bba9 --- /dev/null +++ b/Day2-Object-Constructor/README.md @@ -0,0 +1,2 @@ +# Document-Object-Modeling +This repository is created for lab assignement on DOM for my Code 201 course with Code Partners diff --git a/Day2-Object-Constructor/index.html b/Day2-Object-Constructor/index.html new file mode 100644 index 0000000..e69de29 diff --git a/Day2-Object-Constructor/main.css b/Day2-Object-Constructor/main.css new file mode 100644 index 0000000..e69de29 diff --git a/Day2-Object-Constructor/object-constructor.js b/Day2-Object-Constructor/object-constructor.js new file mode 100644 index 0000000..199538b --- /dev/null +++ b/Day2-Object-Constructor/object-constructor.js @@ -0,0 +1,86 @@ +//creating an object constructor + +let Store = function (location, Average_Cookies_Per_Customer,Avg_Number_Of_Customers){ + this.location = location; + this.Average_Cookies_Per_Customer = Average_Cookies_Per_Customer; + this.Avg_Number_Of_Customers = Avg_Number_Of_Customers; + this.Average_Cookies_Sold_Per_Hour = function () { + return this.Average_Cookies_Per_Customer * this.Avg_Number_Of_Customers; + }; +} + +//creating an array to store the value of my new objects +let storeArray = [] + +//creating instances of the object above +let store1 = new Store( 'Bethesda', 2, 12); +let store2 = new Store('Rockville', 3, 22); +let store3 = new Store('Washington D.c', 4,8) + +storeArray.push(store1); +storeArray.push(store2); +storeArray.push(store3); + +//using console.log to check myArray +console.log(storeArray); + +//creating body element in sale.html and giving it an id, and an attribute +let elBody = doucument.createele + + +/* +let cookieShop1 = { + location: 'Bethesda', + Average_Cookies_Per_Customer:2, + min_Number_Of_Customers : 2, + max_Number_Of_Customers : 12, + Random_Number_of_customers : function () { + return Math.floor(Math.random () * (this.max_Number_Of_Customers - this.min_Number_Of_Customers +1 ) + this.min_Number_Of_Customers) + }, + Average_Cookies_Sold_Per_Hour: this.Random_Number_of_customers * this.Average_Cookies_Per_Customer, +}; +//creating an object and giving it properties, methods +let cookieShop2 = { + location: 'Rockiville', + Average_Cookies_Per_Customer:2, + min_Number_Of_Customers : 4, + max_Number_Of_Customers : 22, + Avg_CookiesSale : function () { + return Math.floor(Math.random () * (this.max_Number_Of_Customers - this.min_Number_Of_Customers +1 ) + this.min_Number_Of_Customers) + }, + Average_Cookies_Sold_Per_Hour: this.Random_Number_of_customers * this.Average_Cookies_Per_Customer, + +}; + +//creating an object and giving it properties, methods +let cookieShop3 = { + location: 'Washington DC', + average_Cookies_Per_Customer:2, + min_Number_Of_Customers : 6, + max_Number_Of_Customers : 110, + Avg_CookiesSale : function () { + return Math.floor(Math.random () * (this.max_Number_Of_Customers - this.min_Number_Of_Customers +1 ) + this.min_Number_Of_Customers) + }, + Average_Cookies_Sold_Per_Hour: this.Random_Number_of_customers * this.Average_Cookies_Per_Customer, + +}; + +//storing the result for each location in an array +let cookie_Sale_Per_Store = [cookieShop1, cookieShop2, cookieShop3]; +for (let i=0; i + + + + + Page Title + + + + + + + + + + + \ No newline at end of file diff --git a/object-literals.js b/object-literals.js index 1f053d5..512136a 100644 --- a/object-literals.js +++ b/object-literals.js @@ -1,5 +1,25 @@ -//creating an object and giving it properties, methods +//creating an object constructor + +let Store = function (location, Average_Cookies_Per_Customer,Avg_Number_Of_Customers){ + this.location = location; + this.Average_Cookies_Per_Customer = Average_Cookies_Per_Customer; + this.Avg_Number_Of_Customers = Avg_Number_Of_Customers; + this.Average_Cookies_Sold_Per_Hour = function () { + return this.Average_Cookies_Per_Customer * this.Avg_Number_Of_Customers; + }; +} + +//creating an array to store the value of my new objects +let storeArray = [] + +//creating instances of the object above +let store1 = new Store( 'Bethesda', 2, 12); +let store2 = new Store('Rockville', 3, 22); +let store3 = new Store('Washington D.c', 4,8) + +console.log(); +/* let cookieShop1 = { location: 'Bethesda', Average_Cookies_Per_Customer:2, @@ -53,5 +73,5 @@ for (let i=0; i Date: Thu, 5 Jul 2018 22:08:06 -0400 Subject: [PATCH 4/5] created loops for the array that stores the object, and appended a table to the body and dynamically named the heder of the table with the first property (location) of the objects in my array --- Day2-Object-Constructor/object-constructor.js | 21 +++++++++++++++++-- Day2-Object-Constructor/sales.html | 11 +++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Day2-Object-Constructor/object-constructor.js b/Day2-Object-Constructor/object-constructor.js index 199538b..42181de 100644 --- a/Day2-Object-Constructor/object-constructor.js +++ b/Day2-Object-Constructor/object-constructor.js @@ -5,7 +5,7 @@ let Store = function (location, Average_Cookies_Per_Customer,Avg_Number_Of_Custo this.Average_Cookies_Per_Customer = Average_Cookies_Per_Customer; this.Avg_Number_Of_Customers = Avg_Number_Of_Customers; this.Average_Cookies_Sold_Per_Hour = function () { - return this.Average_Cookies_Per_Customer * this.Avg_Number_Of_Customers; + return this.Average_Cookies_Per_Customer * this.Avg_Number_Of_Customers; }; } @@ -25,7 +25,24 @@ storeArray.push(store3); console.log(storeArray); //creating body element in sale.html and giving it an id, and an attribute -let elBody = doucument.createele +let elBody = document.getElementById ('creatingTable'); +let elTable = document.createElement('table'); + +//attaching the firstChild of element'table' to table. That first child is table +elBody.appendChild(elTable); + +//looping through the array of my object +for (var i=0; i - - + + + + + + +
      - + \ No newline at end of file From 1855907320892796839b5e9312e962c3bc1c2dc8 Mon Sep 17 00:00:00 2001 From: Patrice Thomas Date: Thu, 5 Jul 2018 23:00:24 -0400 Subject: [PATCH 5/5] dynamically added values for my cells of the rows --- Day2-Object-Constructor/object-constructor.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Day2-Object-Constructor/object-constructor.js b/Day2-Object-Constructor/object-constructor.js index 42181de..24fcd43 100644 --- a/Day2-Object-Constructor/object-constructor.js +++ b/Day2-Object-Constructor/object-constructor.js @@ -33,18 +33,33 @@ elBody.appendChild(elTable); //looping through the array of my object for (var i=0; i