From d4f1c4e8a8171957b1ff69ad86cbcad22d34d653 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 3 Mar 2022 11:31:36 +0000 Subject: [PATCH 01/22] variable assignment completed --- package-lock.json | 1 + spec/variables/assignment.spec.js | 3 +++ src/variables/assignment.js | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index d663c98a..6751df13 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "js-fundamentals", "version": "1.0.0", "license": "ISC", "devDependencies": { diff --git a/spec/variables/assignment.spec.js b/spec/variables/assignment.spec.js index 265ae766..d88558ba 100644 --- a/spec/variables/assignment.spec.js +++ b/spec/variables/assignment.spec.js @@ -9,3 +9,6 @@ describe("Variable Assignment:", () => { expect(b).toEqual(42) }) }) + +//jasmine is for unit testing +// it() is the spec \ No newline at end of file diff --git a/src/variables/assignment.js b/src/variables/assignment.js index 98f2e31c..50ad35c0 100644 --- a/src/variables/assignment.js +++ b/src/variables/assignment.js @@ -3,9 +3,9 @@ let firstNumber = 10 firstNumber = 0 // TODO: Set the value of firstNumber below so the tests pass - +firstNumber = 20 // TODO: Change the code below so that the tests pass -const secondNumber = 0 // edit this value +const secondNumber = 42 // edit this value // do not edit the exported object. module.exports = { From 1422485862500ff351a466a6ac1f266d9070fea7 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 3 Mar 2022 11:48:58 +0000 Subject: [PATCH 02/22] declarations assignment completed --- src/variables/declaration.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/variables/declaration.js b/src/variables/declaration.js index 8afaa55b..638101aa 100644 --- a/src/variables/declaration.js +++ b/src/variables/declaration.js @@ -2,13 +2,15 @@ // // // TODO: Declare the variables firstName and age so that the tests pass - +let firstName = `Jane` +let age = 35 // do not edit below this line let firstNameExport = '' try { firstNameExport = firstName } catch (e) {} let ageExport = 0 try { ageExport = age } catch (e) {} +//try { tries to run this code } if there's an error it is 'caught' and defined as e? module.exports = { firstName: firstNameExport, From e7215cf7d15b563094f40b0cf72da3460c285971 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 3 Mar 2022 11:55:58 +0000 Subject: [PATCH 03/22] datatypes - numbers completed --- src/data-types/numbers.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/data-types/numbers.js b/src/data-types/numbers.js index 01dd70de..8ec2eaa6 100644 --- a/src/data-types/numbers.js +++ b/src/data-types/numbers.js @@ -6,22 +6,22 @@ const numThree = 32 // TODO: Add code below using Javascript numeric operators so that the tests pass // Set this variable to numOne added to numTwo -const numOnePlusNumTwo = NaN +const numOnePlusNumTwo = numOne + numTwo // Set this variable to numThree multiplied by numTwo -const numThreeTimesNumTwo = NaN +const numThreeTimesNumTwo = numThree * numTwo // Set this variable to numThree divided by numOne -const numThreeDividedByNumOne = NaN +const numThreeDividedByNumOne = numThree / numOne // Set this variable to numThree minus numOne -const numThreeMinusNumOne = NaN +const numThreeMinusNumOne = numThree - numOne // Set this variable to the sum of numOne, numTwo and numThree -const sum = NaN +const sum = numOne + numTwo + numThree // Set this variable to the sum of (numOne, numTwo, numThree) divided by numOne -const numBytes = NaN +const numBytes = (numOne + numTwo + numThree) / numOne // do not edit the exported object. module.exports = { From fa8225a7426d0b7d4159401b8c9e4df7c4cba737 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 3 Mar 2022 12:04:24 +0000 Subject: [PATCH 04/22] datatypes strings done --- src/data-types/strings.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/data-types/strings.js b/src/data-types/strings.js index a8eb8c5b..d20f17d3 100644 --- a/src/data-types/strings.js +++ b/src/data-types/strings.js @@ -6,16 +6,16 @@ const secondName = 'Smith' // TODO: Update the code using Javascript string operations and the variables above so that the tests pass. // Set this variable to firstName and secondName concatenated -const fullName = null +const fullName = firstName + ` ` + secondName // Set this variable to the 10th character of the alphabet variable -const tenthCharacterOfAlphabet = null +const tenthCharacterOfAlphabet = alphabet.charAt(9) // Set this variable by calling a method on the alphabet variable to transform it to lower case -const lowerCaseAlphabet = null +const lowerCaseAlphabet = alphabet.toLowerCase() // Set this variable by using a property on the alphabet variable to get it's length -const numberOfLettersInAlphabet = null +const numberOfLettersInAlphabet = alphabet.length // do not edit the exported object. module.exports = { From c7dcf2df4e92b0a580765a3478d898413a481fec Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 3 Mar 2022 12:11:30 +0000 Subject: [PATCH 05/22] accessing elements done --- src/data-types/arrays/accessing-elements.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/data-types/arrays/accessing-elements.js b/src/data-types/arrays/accessing-elements.js index 374a19bb..bfa479e8 100644 --- a/src/data-types/arrays/accessing-elements.js +++ b/src/data-types/arrays/accessing-elements.js @@ -4,16 +4,16 @@ const cities = ['London', 'Shanghai', 'New York', 'Delhi', 'Kuala Lumpur'] // TODO: write code to pass the tests // Set names equal to an array containing 'Bob', 'Jane', 'Joanna' in that order -const names = null +const names = ['Bob', 'Jane', 'Joanna'] // Set fourthCity to the 4th element in the cities array -const fourthCity = '' +const fourthCity = cities[3] // Set firstCity to the 1st element in the cities array -const firstCity = '' +const firstCity = cities[0] // Set lengthOfCitiesArray to the length of the cities array -const lengthOfCitiesArray = NaN +const lengthOfCitiesArray = cities.length // Do not edit this exported object module.exports = { From f2575c56235b006c26b89ecec436e7b1f795ac6b Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 3 Mar 2022 12:27:40 +0000 Subject: [PATCH 06/22] adding removing elements done --- src/data-types/arrays/adding-removing-elements.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/data-types/arrays/adding-removing-elements.js b/src/data-types/arrays/adding-removing-elements.js index 69e559e8..a0ba7943 100644 --- a/src/data-types/arrays/adding-removing-elements.js +++ b/src/data-types/arrays/adding-removing-elements.js @@ -10,25 +10,25 @@ const fruits = ['Apple', 'Orange', 'Pear'] // TODO: write code to pass the tests // Edit this code to add 'Fred' to the names array -names.push(undefined) +names.push('Fred') // Edit this code to add 4 to the end of the numbers array -numbers.push(NaN) +numbers.push(4) // Edit this code to add 'Rio' to the start of the cities array -cities.unshift(undefined) +cities.unshift('Rio') // Use an array method to remove the first item from colours -colours +colours.shift() // Use an array method to remove the last item from keys -keys +keys.pop() // Use an array method to remove 'Jordon' from the countries array -countries.splice(NaN, NaN) +countries.splice(1,1) // use an array method to remove the last item from the fruits array and store the value in the pear variable -const pear = fruits.undefined +const pear = fruits.pop() // Do not edit this exported object module.exports = { From 5a8bc6120453e8303d19095c9206ba0b128dec73 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 3 Mar 2022 15:07:24 +0000 Subject: [PATCH 07/22] object-keys done --- src/data-types/objects/object-keys.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/data-types/objects/object-keys.js b/src/data-types/objects/object-keys.js index 4999e940..b3b97e26 100644 --- a/src/data-types/objects/object-keys.js +++ b/src/data-types/objects/object-keys.js @@ -2,13 +2,13 @@ const book = { name: 'Clean Code', author: 'Robert C. Martin', - category: 'Cooking', + category: 'Programming', isbn: { isbn10: '9780132350884', - asin: '0132350882' + isbn13: '978-0132350884', }, publisher: 'Prentice Hall', - dimensions: '10x12x2' + pages: 464 } const isbn13 = '978-0132350884' @@ -17,10 +17,10 @@ const isbn13 = '978-0132350884' // as well as modify some of the existing code // Set this to the book name -const name = '' +const name = book.name // Set this to the isbn 10 value -const isbn10 = '' +const isbn10 = book.isbn.isbn10 // Do not edit this exported object module.exports = { From 838c9f96bfd29ea4db97ffe1632cf9383c5c9033 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 3 Mar 2022 15:14:40 +0000 Subject: [PATCH 08/22] creating objects done --- src/data-types/objects/creating-objects.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/data-types/objects/creating-objects.js b/src/data-types/objects/creating-objects.js index 1939e6b0..88991464 100644 --- a/src/data-types/objects/creating-objects.js +++ b/src/data-types/objects/creating-objects.js @@ -1,7 +1,16 @@ // TODO: write code in this section to pass the tests. You will need to add new code // as well as modify some of the existing code -const person = null -const computer = null +const person = { + name: 'Jane', + age: 32 +} +const computer = { + form: 'laptop', + specs: { + memory: "16GB", + storage: "1TB" + } +} // Do not edit this exported object module.exports = { From c8a9496290d5a519c43b541d913f34fb52679b78 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 3 Mar 2022 15:18:38 +0000 Subject: [PATCH 09/22] obj and arrays done --- src/data-types/objects/objects-and-arrays.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/data-types/objects/objects-and-arrays.js b/src/data-types/objects/objects-and-arrays.js index e4819467..241ed5d3 100644 --- a/src/data-types/objects/objects-and-arrays.js +++ b/src/data-types/objects/objects-and-arrays.js @@ -4,12 +4,17 @@ const basket = { { name: 'Apple', quantity: 10, - price: 1 + price: 2 }, { name: 'Lemon', quantity: 2, price: 0.5 + }, + { + name: "Oranges", + price: 0.75, + quantity: 4 } ], voucherCodes: [ @@ -22,10 +27,10 @@ const basket = { // as well as modify some of the existing code // Set this variable to the length of the baskets voucher codes array -const numberOfVoucherCodes = null +const numberOfVoucherCodes = basket.voucherCodes.length // Set this variable to the first element in of the baskets voucher codes array -const firstVoucherCode = null +const firstVoucherCode = basket.voucherCodes[0] // Do not edit this exported object module.exports = { From a6ee039d23684910af5ed811c738dc24cbafa288 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 3 Mar 2022 15:42:03 +0000 Subject: [PATCH 10/22] for loop basics done --- src/loops/for-loop-basic.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/loops/for-loop-basic.js b/src/loops/for-loop-basic.js index 38a5c971..c927c3dc 100644 --- a/src/loops/for-loop-basic.js +++ b/src/loops/for-loop-basic.js @@ -4,13 +4,23 @@ const evenNums = [] const countdown = [] // TODO: Write a for loop that adds the numbers 0 to 3 to the numsZeroToThree array +for (let i = 0; i < 4; i++) { + numsZeroToThree.push(i) +} // TODO: Write a for loop that adds the numbers 5 to 10 to the numsFiveToTen array - +for (let i = 5; i < 11; i++) { + numsFiveToTen .push(i) +} // TODO: Write a for loop that adds all the even numbers between 0 and 6 (0, 2, 4, 6) to evenNums - +for (let i = 0; i < 7; i++) { + if (i % 2 === 0) + evenNums.push(i) +} // TODO: Write a for loop that adds the numbers 3 to 0 (in that order) to the countdown array - +for (let i = 3; i > -1; i--) { + countdown.push(i) +} // do not change below this line module.exports = { a: numsZeroToThree, From 16483a72a8a5c827b0932009fe0f99b1b0457759 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 3 Mar 2022 17:39:47 +0000 Subject: [PATCH 11/22] loop and arrays dopne --- src/loops/for-loop-and-arrays.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/loops/for-loop-and-arrays.js b/src/loops/for-loop-and-arrays.js index 682995ec..ca7b84e2 100644 --- a/src/loops/for-loop-and-arrays.js +++ b/src/loops/for-loop-and-arrays.js @@ -8,18 +8,42 @@ let word = '' // Use a for loop to set the sum variable to the sum of all the values in nums sum = 0 +for (let i =0; i < nums.length; i++){ + sum += nums[i] +} + // Use a for loop to populate doubledNums with every value from nums array doubled (i.e [2, 6, 24, etc...]) +// const doubledNums = [] const doubledNums = [] +for (let i = 0; i < nums.length; i++){ + doubledNums.push((nums[i]*2)) +} + // Use a for loop to set word equal to all the letters in the letters array word = '' +for (let i = 0; i < letters.length; i++){ + word += letters[i] +} + // Use a for loop to populate everySecondNum with every second number from the nums array const everySecondNum = [] +for (let i = 1; i < nums.length; i+=2){ + // if(i % 2 === 1){ + // } + everySecondNum.push(nums[i]) +} + // Use a for loop to populate numsReversed with the numbers from nums in reverse order const numsReversed = [] +for (let i = nums.length - 1; i >= 0; i--){ + numsReversed.push(nums[i]) +} + + // do not change below this line module.exports = { a: sum, From 90e3f1d939d96e8ae1f4d4520b9db1064ad1b373 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 3 Mar 2022 17:52:09 +0000 Subject: [PATCH 12/22] calling functions --- src/functions/calling-functions.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/functions/calling-functions.js b/src/functions/calling-functions.js index f44038d6..4cc96add 100644 --- a/src/functions/calling-functions.js +++ b/src/functions/calling-functions.js @@ -19,13 +19,13 @@ function sayHelloManyTimes (name, times) { // TODO: Add and update code here to make the tests pass // Set this variable to 'Hello' by calling the sayHello function -const hello = '' +const hello = sayHello() // Set this variable variable to 'Hello Jane' calling the sayHelloTo function -const helloToJane = '' +const helloToJane = sayHelloTo('Jane') // Set this variable to 'Hello Bob! Hello Bob! Hello Bob!' calling the sayHelloManyTimes function -const helloToBob3Times = '' +const helloToBob3Times = sayHelloManyTimes('Bob', 3) // do not edit below this line module.exports = { From 52d2f45baa34a52a0fd7cb02cf7ea23cab78d503 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 4 Mar 2022 12:02:21 +0000 Subject: [PATCH 13/22] creating functions done --- src/functions/creating-functions.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/functions/creating-functions.js b/src/functions/creating-functions.js index 2d2ac5e6..12f7339b 100644 --- a/src/functions/creating-functions.js +++ b/src/functions/creating-functions.js @@ -7,7 +7,9 @@ // 2 | 3 // // TODO: write code below - +function incrementer (a){ + return a + 1 +} // Define a function that takes any person's name and returns it with a smiley :)! // Remember to make the name capitalized! // @@ -19,8 +21,13 @@ // // TODO: write code below +const hi = function (name) { + const str = `Hi, ${name} :)` + return str.slice(0,4) + str.charAt(4).toUpperCase() + str.slice(5); +} + // TODO: change undefined to be the name of the functions you defined module.exports = { - a: undefined, // change undefined to be the name of the function you defined to increment a number (the first TODO) - b: undefined // change undefined to be the name of the function you defined to say hi (the second TODO) + a: incrementer, // change undefined to be the name of the function you defined to increment a number (the first TODO) + b: hi // change undefined to be the name of the function you defined to say hi (the second TODO) } From a22078b5fc8d50e7e80747c04446d7ad10758365 Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 6 Mar 2022 09:56:18 +0000 Subject: [PATCH 14/22] functions multiple arguments done --- .../creating-functions-multiple-args.js | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/functions/creating-functions-multiple-args.js b/src/functions/creating-functions-multiple-args.js index a437ae8a..d5643726 100644 --- a/src/functions/creating-functions-multiple-args.js +++ b/src/functions/creating-functions-multiple-args.js @@ -10,6 +10,14 @@ // // TODO: write code below +const arrayMaker = function (lower, upper){ +const numsArray = [] + for (let i=lower; i <= upper; i++){ + numsArray.push(i) + } + return numsArray +} + // define a function that takes two arguments: a string and a number. // The function should return the same string but in upper case with exclamation // marks appended to the end. The number of exclamation marks should be @@ -22,8 +30,20 @@ // // TODO: write code below +const alert = function (str, num){ + + stringUpper = str.toUpperCase(); + + for (let i = 0; i < num; i++){ + stringUpper += '!'; + } + + return stringUpper; + } + + // change the exported value to be the name of the function you defined module.exports = { - a: undefined, // change undefined to be the name of the function defined to create the range of numbers (the first todo) - b: undefined // change undefined to be the name of the function defined to return the string with exclamations (the second todo) + a: arrayMaker, // change undefined to be the name of the function defined to create the range of numbers (the first todo) + b: alert // change undefined to be the name of the function defined to return the string with exclamations (the second todo) } From 6ba1063ca48d02894d464bfb240c0cc6c9d2d6f4 Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 6 Mar 2022 10:07:40 +0000 Subject: [PATCH 15/22] boolean conditions done --- src/conditional-flow/boolean-conditions.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/conditional-flow/boolean-conditions.js b/src/conditional-flow/boolean-conditions.js index 70b623d4..0738dbf9 100644 --- a/src/conditional-flow/boolean-conditions.js +++ b/src/conditional-flow/boolean-conditions.js @@ -4,9 +4,16 @@ function getResult (didPass) { // TODO: write code in this function body to pass the tests + + // if (didPass) { + // return "Well done, you passed!"; + // } else { + // return "Sorry, try again"; + // } -} + return (didPass ? "Well done, you passed!" : "Sorry, try again"); +} module.exports = { a: getResult } From 6f88678a52dd1a6787b746528bf6946e792c34b5 Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 6 Mar 2022 10:16:40 +0000 Subject: [PATCH 16/22] numeric conditions done --- src/conditional-flow/numeric-conditions.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/conditional-flow/numeric-conditions.js b/src/conditional-flow/numeric-conditions.js index 0f6656a5..cc61af46 100644 --- a/src/conditional-flow/numeric-conditions.js +++ b/src/conditional-flow/numeric-conditions.js @@ -4,21 +4,22 @@ function isArrayEmpty (array) { // TODO: write code in this function body to pass the tests - + return (array.length === 0 ? true : false); } // This function should return true if num1 is greater than num2, false otherwise function isGreaterThan (num1, num2) { // TODO: write code in this function body to pass the tests - + return (num1 > num2 ? true : false); } // This function should return the lowest number in the passed array function findLowest (nums) { // TODO: write code in this function body to pass the tests - + numLowest = Math.min(...nums) + return numLowest } module.exports = { From 2039855cc94d4cc7541431069ec6f68630a9d8ba Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 6 Mar 2022 11:53:35 +0000 Subject: [PATCH 17/22] string conditions done --- src/conditional-flow/string-conditions.js | 57 +++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/conditional-flow/string-conditions.js b/src/conditional-flow/string-conditions.js index d91bfaf0..beca0614 100644 --- a/src/conditional-flow/string-conditions.js +++ b/src/conditional-flow/string-conditions.js @@ -3,6 +3,8 @@ function isHello (val1) { // TODO: write code in this function body to pass the tests + return ( val1 === "Hello" ? true : false) + } // This function should return true if the passed string is not equal to "Hello" @@ -10,6 +12,8 @@ function isNotHello (val1) { // TODO: write code in this function body to pass the tests + return ( val1 !== "Hello" ? true : false) + } // This function should return true if the string val1 is is longer @@ -18,6 +22,8 @@ function isLongerThan (val1, val2) { // TODO: write code in this function body to pass the tests + return ( val1.length > val2.length ? true : false) + } // This function should return true if the string passed in the function's first @@ -27,7 +33,12 @@ function hasOddNumberVowels (val1) { // TODO: write code in this function body to pass the tests + const count = val1.match(/[aeiou]/gi).length; + + return (count % 2 !== 0 ? true : false); + } +// regEx - regular expression way to search through strings // this function should return the middle character of a string if it has an odd number // of characters. If there are an even number of characters the function should return @@ -35,7 +46,23 @@ function hasOddNumberVowels (val1) { function getMiddleLetter (val1) { // TODO: write code in this function body to pass the tests +// let numMiddle = 0 +// let numsMiddle = 0 + + if (val1.length % 2 === 0 ){ + numMiddle = (val1.length / 2) - 1; + numMiddle2 = numMiddle + 1; + + return `${val1.charAt(numMiddle)}${val1.charAt(numMiddle2)}`; + + + } else { + + numMiddle = val1.length / 2 ; + + return `${val1.charAt(numMiddle)}`; + } } // This function should return the name of the season for the provided @@ -50,6 +77,36 @@ function getMiddleLetter (val1) { function seasonForMonth (monthName) { // TODO: write code in this function body to pass the tests + + switch (monthName) { + case 'March': + case 'April': + case 'May': + szn = "Spring"; + break; + + case 'June': + case 'July': + case 'August': + szn = "Summer"; + break; + + case 'September': + case 'October': + case 'November': + szn = "Autumn"; + break; + + case 'December': + case 'January': + case 'February': + szn = "Winter"; + break; + + default: + szn = ""; + } + return szn } module.exports = { From a95e453f707fbc7665c9665c48ccb39cca4ad752 Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 6 Mar 2022 16:55:48 +0000 Subject: [PATCH 18/22] multiple conditions done --- src/conditional-flow/multiple-conditions.js | 28 ++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/conditional-flow/multiple-conditions.js b/src/conditional-flow/multiple-conditions.js index 80420abf..282c42b7 100644 --- a/src/conditional-flow/multiple-conditions.js +++ b/src/conditional-flow/multiple-conditions.js @@ -4,7 +4,7 @@ function isInRange (num, lower, upper) { // TODO: write code in this function body to pass the tests - +return (num >= lower && num <= upper ? true : false); } // This function should return true if the passed string is equal @@ -14,6 +14,11 @@ function isHelloOrGoodbye (val1) { // TODO: write code in this function body to pass the tests + if (val1 === "Hello" || val1 === "Goodbye") { + return true + } else { + return false + } } // This function should return a string that describes the provided age value. The @@ -31,6 +36,27 @@ function isHelloOrGoodbye (val1) { function getAgeDescription (age) { // TODO: write code in this function body to pass the tests + + if (age === 0){ + return "Baby" + } + + else if(age <= 4){ + return "Toddler" + } + + else if(age <= 12){ + return "Child" + } + + else if(age <= 19){ + return "Teenager" + } + + else { + return "Adult" + } + } module.exports = { From 700da31554feaf9bce1a77c79ad01fdfb0e86932 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 8 Mar 2022 15:11:56 +0000 Subject: [PATCH 19/22] demo done --- src/demo/demo.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/demo/demo.js b/src/demo/demo.js index 9201bd8a..64ed9e51 100644 --- a/src/demo/demo.js +++ b/src/demo/demo.js @@ -1,17 +1,17 @@ // do not edit this section -const numOne = 10 -const numTwo = 2 -let numThree = 0 +const numOne = 10; +const numTwo = 2; +let numThree = 0; // TODO: Update numThree so the tests pass -numThree = 0 +numThree = 5; // TODO: Update the code below so that the tests pass -const numOnePlusNumTwo = 0 // Set this variable to numOne plus numTwo +const numOnePlusNumTwo = 12; // Set this variable to numOne plus numTwo // do not edit this section module.exports = { a: numThree, - b: numOnePlusNumTwo -} + b: numOnePlusNumTwo, +}; From 9bf3d9e1d9eeb5be2ca510a0030cdd07678cfe2d Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 9 Mar 2022 16:22:17 +0000 Subject: [PATCH 20/22] fixed object keys exercise --- spec/data-types/objects/object-keys.spec.js | 48 ++++++++++----------- src/data-types/objects/object-keys.js | 41 ++++++++++++------ 2 files changed, 52 insertions(+), 37 deletions(-) diff --git a/spec/data-types/objects/object-keys.spec.js b/spec/data-types/objects/object-keys.spec.js index b8e8b0dc..f1e47d21 100644 --- a/spec/data-types/objects/object-keys.spec.js +++ b/spec/data-types/objects/object-keys.spec.js @@ -1,31 +1,31 @@ -const answers = require('../../../src/data-types/objects/object-keys.js') +const answers = require("../../../src/data-types/objects/object-keys.js"); -describe('Objects Keys:', () => { - it('name should be equal to the book name', () => { - expect(answers.name).toEqual('Clean Code') - }) +describe("Objects Keys:", () => { + it("name should be equal to the book name", () => { + expect(answers.name).toEqual("Clean Code"); + }); - it('ISBN 10 should be equal to the book\'s ISBN 10 number', () => { - expect(answers.isbn10).toEqual('9780132350884') - }) + it("ISBN 10 should be equal to the book's ISBN 10 number", () => { + expect(answers.isbn10).toEqual("9780132350884"); + }); - it('Book category should be Programming', () => { - expect(answers.book.category).toEqual('Programming') - }) + it("Book category should be Programming", () => { + expect(answers.book.category).toEqual("Programming"); + }); - it('Book pages should be 464', () => { - expect(answers.book.pages).toEqual(464) - }) + it("Book pages should be 464", () => { + expect(answers.book.pages).toEqual(464); + }); - it('Book ISBN 13 should be 978-0132350884', () => { - expect(answers.book.isbn.isbn13).toEqual('978-0132350884') - }) + it("Book ISBN 13 should be 978-0132350884", () => { + expect(answers.book.isbn.isbn13).toEqual("978-0132350884"); + }); - it('Book should not contain the dimensions key - it should be deleted', () => { - expect(answers.book.dimensions).not.toBeDefined() - }) + it("Book should not contain the dimensions key - it should be deleted", () => { + expect(answers.book.dimensions).not.toBeDefined(); + }); - it('Book should not contain the asin key - it should be deleted', () => { - expect(answers.book.isbn.asin).not.toBeDefined() - }) -}) + it("Book should not contain the asin key - it should be deleted", () => { + expect(answers.book.isbn.asin).not.toBeDefined(); + }); +}); diff --git a/src/data-types/objects/object-keys.js b/src/data-types/objects/object-keys.js index b3b97e26..49552cf8 100644 --- a/src/data-types/objects/object-keys.js +++ b/src/data-types/objects/object-keys.js @@ -1,30 +1,45 @@ // do not edit this section const book = { - name: 'Clean Code', - author: 'Robert C. Martin', - category: 'Programming', + name: "Clean Code", + author: "Robert C. Martin", + category: "Cooking", isbn: { - isbn10: '9780132350884', - isbn13: '978-0132350884', + isbn10: "9780132350884", + asin: "0132350882", }, - publisher: 'Prentice Hall', - pages: 464 -} + publisher: "Prentice Hall", + dimensions: "10x12x2", +}; -const isbn13 = '978-0132350884' +const isbn13 = "978-0132350884"; // TODO: write code in this section to pass the tests. You will need to add new code // as well as modify some of the existing code // Set this to the book name -const name = book.name +const name = book.name; // Set this to the isbn 10 value -const isbn10 = book.isbn.isbn10 +const isbn10 = book.isbn.isbn10; + +// Set category to Programming +book.category = "Programming"; + +// Adding pages +book.pages = 464; + +// Adding isbn13 number +book.isbn.isbn13 = isbn13; + +// Delete book dimensions +delete book.dimensions; + +// Delete asin number +delete book.isbn.asin; // Do not edit this exported object module.exports = { name: name, isbn10: isbn10, - book: book -} + book: book, +}; From f5120a54793ffdfabe9cbe10c40ccbc84f06433a Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 9 Mar 2022 16:27:41 +0000 Subject: [PATCH 21/22] objects and arrays fixed --- src/data-types/objects/objects-and-arrays.js | 38 ++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/data-types/objects/objects-and-arrays.js b/src/data-types/objects/objects-and-arrays.js index 241ed5d3..db1c13d2 100644 --- a/src/data-types/objects/objects-and-arrays.js +++ b/src/data-types/objects/objects-and-arrays.js @@ -2,39 +2,41 @@ const basket = { items: [ { - name: 'Apple', + name: "Apple", quantity: 10, - price: 2 + price: 1, }, { - name: 'Lemon', + name: "Lemon", quantity: 2, - price: 0.5 + price: 0.5, }, - { - name: "Oranges", - price: 0.75, - quantity: 4 - } ], - voucherCodes: [ - 'AA-AA-A', - 'BB-BB-B' - ] -} + voucherCodes: ["AA-AA-A", "BB-BB-B"], +}; // TODO: write code in this section to pass the tests. You will need to add new code // as well as modify some of the existing code // Set this variable to the length of the baskets voucher codes array -const numberOfVoucherCodes = basket.voucherCodes.length +const numberOfVoucherCodes = basket.voucherCodes.length; // Set this variable to the first element in of the baskets voucher codes array -const firstVoucherCode = basket.voucherCodes[0] +const firstVoucherCode = basket.voucherCodes[0]; + +// updated apple price +basket.items[0].price = 2; + +// adding to array +basket.items[2] = { + name: "Oranges", + price: 0.75, + quantity: 4, +}; // Do not edit this exported object module.exports = { basket: basket, numberOfVoucherCodes: numberOfVoucherCodes, - firstVoucherCode: firstVoucherCode -} + firstVoucherCode: firstVoucherCode, +}; From 7addf74474dc878c12ca0e87d6799e6985ee07c6 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 9 Mar 2022 16:29:56 +0000 Subject: [PATCH 22/22] refactored code as discussed --- src/conditional-flow/multiple-conditions.js | 48 ++++++++------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/src/conditional-flow/multiple-conditions.js b/src/conditional-flow/multiple-conditions.js index 282c42b7..6f755f34 100644 --- a/src/conditional-flow/multiple-conditions.js +++ b/src/conditional-flow/multiple-conditions.js @@ -1,23 +1,21 @@ // This function should return true if num is greater // than or equal to lower AND less than or equal to upper. // Implement this with a single condition. -function isInRange (num, lower, upper) { - +function isInRange(num, lower, upper) { // TODO: write code in this function body to pass the tests -return (num >= lower && num <= upper ? true : false); + return num >= lower && num <= upper; } // This function should return true if the passed string is equal // to "Hello" or "Goodbye". Implement this with a single // if statement. -function isHelloOrGoodbye (val1) { - +function isHelloOrGoodbye(val1) { // TODO: write code in this function body to pass the tests if (val1 === "Hello" || val1 === "Goodbye") { - return true + return true; } else { - return false + return false; } } @@ -33,34 +31,24 @@ function isHelloOrGoodbye (val1) { // 5-12 | Child // 13-19 | Teenager // 20+ | Adult -function getAgeDescription (age) { - +function getAgeDescription(age) { // TODO: write code in this function body to pass the tests - if (age === 0){ - return "Baby" - } - - else if(age <= 4){ - return "Toddler" - } - - else if(age <= 12){ - return "Child" - } - - else if(age <= 19){ - return "Teenager" - } - - else { - return "Adult" + if (age === 0) { + return "Baby"; + } else if (age <= 4) { + return "Toddler"; + } else if (age <= 12) { + return "Child"; + } else if (age <= 19) { + return "Teenager"; + } else { + return "Adult"; } - } module.exports = { a: isInRange, b: isHelloOrGoodbye, - c: getAgeDescription -} + c: getAgeDescription, +};