From 662ec56c47e3644cb6fb7e7873d14ac0c792a2db Mon Sep 17 00:00:00 2001 From: Alex Nielsen Date: Thu, 16 Mar 2017 02:04:49 -0400 Subject: [PATCH 1/2] all tests pass --- exercises.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/exercises.js b/exercises.js index be10a41..018a5bf 100644 --- a/exercises.js +++ b/exercises.js @@ -3,6 +3,14 @@ //Do not change any of the function names function makeCat(name, age) { + var lily = { + name: name, + age: age, + meow: function() { + return 'Meow!'; + } + }; + return lily; //create a new object with a name property with the value set to the name argument //add an age property to the object with the value set to the age argument //add a method called meow that returns the string 'Meow!' @@ -10,61 +18,96 @@ function makeCat(name, age) { } function addProperty(object, property) { + object[property] = null; + return object; //add the property to the object with a value of null //return the object //note: the property name is NOT 'property'. The name is the value of the argument called property (a string) } function invokeMethod(object, method) { + object[method](); //method is a string that contains the name of a method on the object //invoke this method //nothing needs to be returned } function multiplyMysteryNumberByFive(mysteryNumberObject) { + return mysteryNumberObject.mysteryNumber * 5; //mysteryNumberObject has a property called mysteryNumber //multiply the mysteryNumber property by 5 and return the product } function deleteProperty(object, property) { + delete object[property]; + return object; //remove the property from the object //return the object } function newUser(name, email, password) { + var user = { + name: name, + email: email, + password: password + }; + return user; //create a new object with properties matching the arguments passed in. //return the new object } function hasEmail(user) { + if (user.email) { + return true; + } else { + return false; + } //return true if the user has a value for the property 'email' //otherwise return false } function hasProperty(object, property) { + if (object[property]) { + return true; + } else { + return false; + } //return true if the object has the value of the property argument //property is a string //otherwise return false } function verifyPassword(user, password) { + if (user.password === password) { + return true; + } else { + return false; + } //check to see if the provided password matches the password property on the user object //return true if they match //otherwise return false } function updatePassword(user, newPassword) { + user.password = newPassword; + return user; //replace the existing password on the user object with the value of newPassword //return the object } function addFriend(user, newFriend) { + user.friends.push(newFriend); + return user; //user has a property called friends that is an array //add newFriend to the end of the friends array //return the user object } function setUsersToPremium(users) { + for (var i = 0 ; i < users.length; i ++) { + users[i].isPremium = true; + } + return users; //users is an array of user objects. //each user object has the property 'isPremium' //set each user's isPremium property to true @@ -72,6 +115,11 @@ function setUsersToPremium(users) { } function sumUserPostLikes(user) { + var count = 0; + for (var i = 0; i < user.posts.length; i++) { + count += user.posts[i].likes; + } + return count; //user has an array property called 'posts' //posts is an array of post objects //each post object has an integer property called 'likes' @@ -80,6 +128,14 @@ function sumUserPostLikes(user) { } function addCalculateDiscountPriceMethod(storeItem) { + storeItem.calculateDiscountPrice = function() { + var discount = storeItem.price * storeItem.discountPercentage; + var discountPrice = storeItem.price - discount; + return discountPrice; + }; + return storeItem; + + //add a method to the storeItem object called 'calculateDiscountPrice' //this method should multiply the storeItem's 'price' and 'discountPercentage' to get the discount //the method then subtracts the discount from the price and returns the discounted price From 98f8ece9b6cd01412c222a4c0da66ebe1a0189a7 Mon Sep 17 00:00:00 2001 From: Alex Nielsen Date: Thu, 16 Mar 2017 13:51:44 -0400 Subject: [PATCH 2/2] add line //return storeItem object Maybe this was implied but I don't think so. Other functions in the assignment explicitly say things like 'return the users array' after the required changes are completed. I had this correct but kept making changes for almost an hour until I saw on the slack channel that you had to return the object after you made the changes --- exercises.js | 57 +--------------------------------------------------- 1 file changed, 1 insertion(+), 56 deletions(-) diff --git a/exercises.js b/exercises.js index 018a5bf..b8ff9e2 100644 --- a/exercises.js +++ b/exercises.js @@ -3,14 +3,6 @@ //Do not change any of the function names function makeCat(name, age) { - var lily = { - name: name, - age: age, - meow: function() { - return 'Meow!'; - } - }; - return lily; //create a new object with a name property with the value set to the name argument //add an age property to the object with the value set to the age argument //add a method called meow that returns the string 'Meow!' @@ -18,96 +10,61 @@ function makeCat(name, age) { } function addProperty(object, property) { - object[property] = null; - return object; //add the property to the object with a value of null //return the object //note: the property name is NOT 'property'. The name is the value of the argument called property (a string) } function invokeMethod(object, method) { - object[method](); //method is a string that contains the name of a method on the object //invoke this method //nothing needs to be returned } function multiplyMysteryNumberByFive(mysteryNumberObject) { - return mysteryNumberObject.mysteryNumber * 5; //mysteryNumberObject has a property called mysteryNumber //multiply the mysteryNumber property by 5 and return the product } function deleteProperty(object, property) { - delete object[property]; - return object; //remove the property from the object //return the object } function newUser(name, email, password) { - var user = { - name: name, - email: email, - password: password - }; - return user; //create a new object with properties matching the arguments passed in. //return the new object } function hasEmail(user) { - if (user.email) { - return true; - } else { - return false; - } //return true if the user has a value for the property 'email' //otherwise return false } function hasProperty(object, property) { - if (object[property]) { - return true; - } else { - return false; - } //return true if the object has the value of the property argument //property is a string //otherwise return false } function verifyPassword(user, password) { - if (user.password === password) { - return true; - } else { - return false; - } //check to see if the provided password matches the password property on the user object //return true if they match //otherwise return false } function updatePassword(user, newPassword) { - user.password = newPassword; - return user; //replace the existing password on the user object with the value of newPassword //return the object } function addFriend(user, newFriend) { - user.friends.push(newFriend); - return user; //user has a property called friends that is an array //add newFriend to the end of the friends array //return the user object } function setUsersToPremium(users) { - for (var i = 0 ; i < users.length; i ++) { - users[i].isPremium = true; - } - return users; //users is an array of user objects. //each user object has the property 'isPremium' //set each user's isPremium property to true @@ -115,11 +72,6 @@ function setUsersToPremium(users) { } function sumUserPostLikes(user) { - var count = 0; - for (var i = 0; i < user.posts.length; i++) { - count += user.posts[i].likes; - } - return count; //user has an array property called 'posts' //posts is an array of post objects //each post object has an integer property called 'likes' @@ -128,14 +80,6 @@ function sumUserPostLikes(user) { } function addCalculateDiscountPriceMethod(storeItem) { - storeItem.calculateDiscountPrice = function() { - var discount = storeItem.price * storeItem.discountPercentage; - var discountPrice = storeItem.price - discount; - return discountPrice; - }; - return storeItem; - - //add a method to the storeItem object called 'calculateDiscountPrice' //this method should multiply the storeItem's 'price' and 'discountPercentage' to get the discount //the method then subtracts the discount from the price and returns the discounted price @@ -143,6 +87,7 @@ function addCalculateDiscountPriceMethod(storeItem) { //price -> 20 //discountPercentage -> .2 //discountPrice = 20 - (20 * .2) + //return storeItem object } //Do not modify code below this line.