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..24fcd43 --- /dev/null +++ b/Day2-Object-Constructor/object-constructor.js @@ -0,0 +1,118 @@ +//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 = 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 + + + + + Page Title + + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/Day3-Forms-Events/form-event.js b/Day3-Forms-Events/form-event.js new file mode 100644 index 0000000..7d57581 --- /dev/null +++ b/Day3-Forms-Events/form-event.js @@ -0,0 +1,109 @@ + +//moving my object constructor from previsous lab to this page as reference +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 the element form +//selecting the element node (form) I want the script to respond to. This variable is facilitating DOM access to the form. +let elStore = document.getElementById("stores"); + +// stating the input field my form needs and making their value equal to the different parameters/keys in my object constructor. +let userSelect = elStore.location1; +let userNumber = elStore.avg_cookies_per_cust; +let UserAvgofCustomer = elStore.avgOfCustomer; + + +//creating an array as placeholder to store the new objects that is create when user puts required values and fire the event "submit" +let storeArray = []; + +//indicating which event on the form node will trigger the response +//stating the function I want to run when event "submit" is fired +elStore.addEventListener('submit', function(event) { + event.preventDefault() + + //creating new instance of the Store Constructor + let newStore = new Store(userSelect.value, userNumber.value, UserAvgofCustomer.value) +storeArray.push(newStore) +addingRow(); +avgCookies(); +numberOfCustomers(); +theTotal(); +console.log(newStore); +console.log(storeArray); + +}); + + + +//creating the table which will dynamically populate the user values entered in the form + +let newBody= document.getElementById('body') +let elTable = document.createElement ('table') + +//attaching the firstChild of element'table' to table. That first child is table +newBody.appendChild(elTable); + +//looping through the array of my object +//for (var i=0; i + + + + + Forms and Events J.S + + + + + + + +
+ +
+

location: + + +
+ +

Average Numbr of Customenrs

+ + + +
+ + +
+ +
+
+ + + + + + + + + + + +
Total
+ + + \ No newline at end of file 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..512136a --- /dev/null +++ b/object-literals.js @@ -0,0 +1,77 @@ +//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, + 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