From 9af45828f2a97ec1c925fdd63f926033684a689e Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 15 May 2019 21:13:39 -0900 Subject: [PATCH 01/13] solved #1 --- exercises.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/exercises.js b/exercises.js index 2ee51b9..a9ba0b4 100644 --- a/exercises.js +++ b/exercises.js @@ -13,8 +13,16 @@ Objects in Javascript can be compared to objects in real life. Objects has a col Console.log the object. */ - +var books = { + title: 'The Obstacle is the Way', + author: 'Ryan Holiday', + category: 'Self Help', + pages: 200, +} + +console.log(books); + /* 2. Declare a variable named `dog` and create the following properties (key-value pairs) to the object: @@ -30,8 +38,6 @@ Objects in Javascript can be compared to objects in real life. Objects has a col "My dog `name` is `age` year old and likes to `speak` at strangers." */ - - //An empty object /* From e4ca2c5ed11982e9230c15945ef727f73f0ca3b9 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 15 May 2019 21:18:51 -0900 Subject: [PATCH 02/13] solved #2 --- exercises.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/exercises.js b/exercises.js index a9ba0b4..ba1468e 100644 --- a/exercises.js +++ b/exercises.js @@ -38,6 +38,18 @@ console.log(books); "My dog `name` is `age` year old and likes to `speak` at strangers." */ +var dog = { + name: 'o3q8weytoq8wetynolsaiufdloqweit', + age: 92357982475274508723095098423, + vegeterian: false, + color: ['black', 'white'], + speak: function(){ + return 'Bark' + } +} + +console.log('My dog ' + dog.name + ' is ' + dog.age + ' years old and likes to ' + dog.speak() + ' at strangers.') + //An empty object /* From 036b9cd1376986e570f13f73fe076a4c706f461b Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 15 May 2019 21:24:35 -0900 Subject: [PATCH 03/13] solved #3 --- exercises.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/exercises.js b/exercises.js index ba1468e..531887a 100644 --- a/exercises.js +++ b/exercises.js @@ -65,6 +65,17 @@ console.log('My dog ' + dog.name + ' is ' + dog.age + ' years old and likes to ' Console.log the object. */ +var kicks = {}; + +kicks.brand = 'nike'; +kicks.color = 'cornflower blue'; +kicks.size = 7.5; +kicks.price = 75; +kicks.buy = function(){ + return 'Now I is a cool kid!'; +} + +console.log(kicks); /* @@ -78,6 +89,7 @@ console.log('My dog ' + dog.name + ' is ' + dog.age + ' years old and likes to ' */ + /* 5. Declare a variable named `stockCar` and create the following properties (key-value pairs) to the object: - add a key named `model` and set its value to the name of an American car manufacturer. From a42ad452e2bfced54cb8ced8adcdfa17a02c5e2e Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 15 May 2019 21:28:01 -0900 Subject: [PATCH 04/13] solved #4 --- exercises.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/exercises.js b/exercises.js index 531887a..61f3abb 100644 --- a/exercises.js +++ b/exercises.js @@ -88,7 +88,13 @@ console.log(kicks); console.log the object */ +var plainBox = {}; +plainBox.color = 'blue'; +plainBox.size = 12; +plainBox.contents = []; + +console.log(plainBox); /* 5. Declare a variable named `stockCar` and create the following properties (key-value pairs) to the object: From 79216c4a241de35f49e20b79898088f9f8e0e358 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 15 May 2019 21:31:02 -0900 Subject: [PATCH 05/13] solved #5 --- exercises.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/exercises.js b/exercises.js index 61f3abb..40c963a 100644 --- a/exercises.js +++ b/exercises.js @@ -107,6 +107,15 @@ console.log(plainBox); console.log the object */ +var stockCar = { + model: 'ford', + year: 2014, + automaticTransmission: true, + driver: null, + passengers: [] +} + +console.log(stockCar); /* From 4805bee1837089a5c0b558c527089b38fce18747 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 15 May 2019 21:46:31 -0900 Subject: [PATCH 06/13] solved #6 --- exercises.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/exercises.js b/exercises.js index 40c963a..fce92d6 100644 --- a/exercises.js +++ b/exercises.js @@ -134,6 +134,17 @@ console.log(stockCar); the value at `name`, and just the value at `age`. */ +var plainPerson = {}; + +function buildPerson(person, nameString, age){ + plainPerson.name = nameString; + plainPerson.age = age; + return person; +} + +var completePerson = buildPerson('boy', 'James', 12); +console.log(completePerson); +console.log(plainPerson); /* 7. Display values of objects that are inside an array From 2daf7fb6924b5b75313ccc7aaa1bf54f5fb9dc33 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 May 2019 18:30:27 -0900 Subject: [PATCH 07/13] solved #7 --- exercises.js | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/exercises.js b/exercises.js index fce92d6..d7eaabd 100644 --- a/exercises.js +++ b/exercises.js @@ -171,6 +171,121 @@ console.log(plainPerson); ... */ +var arrayOfObjects = [ + + { + + id: 0, + + date: "Monday Jan 25 2015 2:01 PM", + + total: "279.38" + + }, + + { + + id: 1, + + date: "Monday Jan 27 2015 11:31 AM", + + total: "79.80" + + }, + + { + + id: 2, + + date: "Monday Feb 1 2015 7:56 AM", + + total: "15.62" + + }, + + { + + id: 3, + + date: "Monday Feb 1 2015 9:43 AM", + + total: "19.83" + + }, + + { + + id: 4, + + date: "Monday Feb 1 2015 11:08 PM", + + total: "56.69" + + }, + + { + + id: 5, + + date: "Monday Feb 13 2015 10:22 AM", + + total: "137.92" + + }, + + { + + id: 6, + + date: "Monday Feb 14 2015 6:54 PM", + + total: "938.65" + + }, + + { + + id: 7, + + date: "Monday Feb 14 2015 7:17 PM", + + total: "43.77" + + }, + + { + + id: 8, + + date: "Monday Feb 14 2015 7:18 PM", + + total: "28.54" + + }, + + { + + id: 9, + + date: "Monday Feb 14 2015 7:18 PM", + + total: "194.33" + + } + + ] + +function printOrders(orders){ + for(var i = 0; i < orders.length; i++){ + console.log('====='); + console.log('id: ' + orders[i].id); + console.log('date: ' + orders[i].date); + console.log('total: ' + orders[i].total); + } + +} + +printOrders(arrayOfObjects); /* 8. Addition with an object From 75216bfc60b2d374233c695506ad3990239cc48c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 May 2019 18:57:53 -0900 Subject: [PATCH 08/13] solved #8 --- exercises.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/exercises.js b/exercises.js index d7eaabd..afdbcaf 100644 --- a/exercises.js +++ b/exercises.js @@ -300,6 +300,19 @@ printOrders(arrayOfObjects); to inspect your results. */ +var sumObj = { + a: 3, + b: 4, + result: undefined, +} + +function objectAddition(obj){ + var sum = obj.a + obj.b; + result = sum; + console.log(result); +} + +objectAddition(sumObj); /* 9. Print sum function and add as new key-value @@ -319,6 +332,7 @@ printOrders(arrayOfObjects); */ + /* 10. Putting stuff in `plainBox` Declare a function named putInPlainBox and a single parameter which will be an object. Within this function, write a From a8acc8689003d6c7e4717ea90a4d58f793494dfd Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 May 2019 18:58:54 -0900 Subject: [PATCH 09/13] solved #9 --- exercises.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/exercises.js b/exercises.js index afdbcaf..3e59d9b 100644 --- a/exercises.js +++ b/exercises.js @@ -331,7 +331,12 @@ objectAddition(sumObj); **create more** objects and invoke your function multiple times. */ +function printObj(obj){ + var sum = obj.a + obj.b; + console.log(obj.a + ' + ' + obj.b + ' = ' + sum); +} +printObj(sumObj); /* 10. Putting stuff in `plainBox` From 8d07dd5884fa2a2bd4e7febfa7f69953cc02a016 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 May 2019 19:14:39 -0900 Subject: [PATCH 10/13] skipped #10 --- exercises.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/exercises.js b/exercises.js index 3e59d9b..0926692 100644 --- a/exercises.js +++ b/exercises.js @@ -348,6 +348,9 @@ printObj(sumObj); plainBoxResult and use `console.log` to inspect your results. */ +function putInPlainBox(object){ + +} /* 11. Detecting transmission From c45c6f97a0390a656fb0b87fd8fb40183f49e169 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 May 2019 21:04:56 -0900 Subject: [PATCH 11/13] solved #11 --- exercises.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/exercises.js b/exercises.js index 0926692..e654de1 100644 --- a/exercises.js +++ b/exercises.js @@ -349,9 +349,16 @@ printObj(sumObj); */ function putInPlainBox(object){ - + for (var i = 0; i < 10; i++){ + var randomNum = Math.floor(Math.random()*10); + object.contents.push(randomNum); + } + return object; } +var plainBoxResult = putInPlainBox(plainBox); +console.log(plainBoxResult); + /* 11. Detecting transmission Declare a function named detectingTransmission and a single parameter which will be an object. Within this function @@ -364,6 +371,7 @@ function putInPlainBox(object){ */ + /* 12. Who's driving this thing?! As you may have noticed that the `stockCar` doesn't have a driver! From aca7df556e9a66e6cc05e5e4e54ab97bd337d6b3 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 May 2019 21:07:27 -0900 Subject: [PATCH 12/13] solved #11 --- exercises.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/exercises.js b/exercises.js index e654de1..e91fc96 100644 --- a/exercises.js +++ b/exercises.js @@ -370,7 +370,15 @@ console.log(plainBoxResult); Invoke your function and pass in your stockCar object, store the result to a variable named isAutomaticTransmission and use `console.log` to inspect your results. */ +function detectingTransmission(object){ + if (object.automaticTransmission === true){ + console.log(true); + }else{ + console.log(false); + } +} +detectingTransmission(stockCar); /* 12. Who's driving this thing?! From 26a2c9a4dec63ffebcefb8d4c44ee351d0b2a745 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 May 2019 21:19:47 -0900 Subject: [PATCH 13/13] solved #12 --- exercises.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/exercises.js b/exercises.js index e91fc96..ed581a2 100644 --- a/exercises.js +++ b/exercises.js @@ -392,7 +392,14 @@ detectingTransmission(stockCar); your results. Consider using `plainPerson` as your driver. */ +function addDriver(obj, person){ + obj.driver = person; + return obj; +} + +var stockCarWithDriver = addDriver(stockCar, plainPerson); +console.log(stockCarWithDriver); /*