From 0e214c51fcfa921b43df92547fcf35046e538201 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 3 Mar 2022 13:01:28 +0100 Subject: [PATCH 01/21] variables/assignment - test passed --- package-lock.json | 1 + src/variables/assignment.js | 4 ++-- 2 files changed, 3 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/src/variables/assignment.js b/src/variables/assignment.js index 98f2e31c..c100ea9a 100644 --- a/src/variables/assignment.js +++ b/src/variables/assignment.js @@ -1,11 +1,11 @@ // do not edit this let firstNumber = 10 -firstNumber = 0 +firstNumber = 20 // TODO: Set the value of firstNumber below so the tests pass // 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 c5577284c92f7ab3f11818cb14decd4308ca6fdb Mon Sep 17 00:00:00 2001 From: David Date: Thu, 3 Mar 2022 13:08:23 +0100 Subject: [PATCH 02/21] variables/declaration - test passed --- src/variables/declaration.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/variables/declaration.js b/src/variables/declaration.js index 8afaa55b..e202ac76 100644 --- a/src/variables/declaration.js +++ b/src/variables/declaration.js @@ -4,10 +4,10 @@ // TODO: Declare the variables firstName and age so that the tests pass // do not edit below this line -let firstNameExport = '' +let firstNameExport = 'Jane' try { firstNameExport = firstName } catch (e) {} -let ageExport = 0 +let ageExport = 35 try { ageExport = age } catch (e) {} module.exports = { From 0d562285210cd272b19574e9d2d3b7193c3576e9 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 3 Mar 2022 16:48:42 +0100 Subject: [PATCH 03/21] data types 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 dd46b9b7e1a6d402880eb1a3b94e388e96e9fc5a Mon Sep 17 00:00:00 2001 From: David Date: Thu, 3 Mar 2022 17:20:18 +0100 Subject: [PATCH 04/21] data-types strings completed --- 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..1f39e826 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 8180159d72a5e33670689dff9b4c0b0a84358329 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 3 Mar 2022 17:55:32 +0100 Subject: [PATCH 05/21] data-types/arrays/accessing element complete --- src/data-types/arrays/accessing-elements.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/data-types/arrays/accessing-elements.js b/src/data-types/arrays/accessing-elements.js index 374a19bb..db2ed5b5 100644 --- a/src/data-types/arrays/accessing-elements.js +++ b/src/data-types/arrays/accessing-elements.js @@ -4,16 +4,17 @@ 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 f268decd109848d670ddbc4ca1258c0e83635807 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 3 Mar 2022 18:10:03 +0100 Subject: [PATCH 06/21] data-types/arrays/adding-removing complete --- 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..8a0ba527 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 84ff415f644e44134c0291a044f0c172d3e0efd7 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 3 Mar 2022 19:02:25 +0100 Subject: [PATCH 07/21] data-types/objects/object-keys completed --- src/data-types/objects/object-keys.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/data-types/objects/object-keys.js b/src/data-types/objects/object-keys.js index 4999e940..5a90f3d0 100644 --- a/src/data-types/objects/object-keys.js +++ b/src/data-types/objects/object-keys.js @@ -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 = { @@ -28,3 +28,21 @@ module.exports = { isbn10: isbn10, book: book } + +// Book category should be Programming +book.category = "Programming" + +//Book pages should be 464 +book.pages = 464 + +//Book ISBN 13 should be 978-0132350884 +book.isbn.isbn13 = "978-0132350884" + +//Book should not contain the dimensions key - it should be deleted +delete book.dimensions + +//Book should not contain the asin key - it should be deleted +delete book.isbn.asin + + + From 7b274aca7bdcf4f2079278363ff9fa99fdee15d3 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 3 Mar 2022 19:15:00 +0100 Subject: [PATCH 08/21] data-types/objects/creating-objects --- src/data-types/objects/creating-objects.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/data-types/objects/creating-objects.js b/src/data-types/objects/creating-objects.js index 1939e6b0..0abf57a0 100644 --- a/src/data-types/objects/creating-objects.js +++ b/src/data-types/objects/creating-objects.js @@ -8,3 +8,20 @@ module.exports = { person: person, computer: computer } + +// Person should be an object with the name "Jane" +person.name = "Jane" + +//Person should be an object with the age 32' +person.age = 32 + + +//Computer should be an object with the form "laptop" +computer.form = "laptop" + + +//Computer.specs should be an object with a memory "16GB" and storage "1TB" +computer.specs { + memory: "16GB", + storage: "1TB" +} \ No newline at end of file From 77e316e0a7b5235ecbadc4edf9b030807b5ee773 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 3 Mar 2022 20:54:48 +0100 Subject: [PATCH 09/21] data-types/objects&arrays completed --- spec/data-types/objects/objects-and-arrays.spec.js | 2 +- src/data-types/objects/objects-and-arrays.js | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/spec/data-types/objects/objects-and-arrays.spec.js b/spec/data-types/objects/objects-and-arrays.spec.js index 8b7d86fb..d696210c 100644 --- a/spec/data-types/objects/objects-and-arrays.spec.js +++ b/spec/data-types/objects/objects-and-arrays.spec.js @@ -12,7 +12,7 @@ describe('Objects and Arrays:', () => { it('The price of apples should be updated to 2', () => { expect(answers.basket.items[0].price).toEqual(2) }) - +- it('4 oranges priced at 0.75 should be added to the end of the items list', () => { expect(answers.basket.items[2]).toEqual({ name: "Oranges", diff --git a/src/data-types/objects/objects-and-arrays.js b/src/data-types/objects/objects-and-arrays.js index e4819467..95de6405 100644 --- a/src/data-types/objects/objects-and-arrays.js +++ b/src/data-types/objects/objects-and-arrays.js @@ -22,10 +22,20 @@ 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] + +//The price of apples should be updated to 2 +basket.items[0].price = 2 + +//4 oranges priced at 0.75 should be added to the end of the items list +basket.items.push({ + name: "Oranges", + price: 0.75, + quantity: 4, +}); // Do not edit this exported object module.exports = { From 73f138a5feaa0cf61541582917bb19eb8b9bbcc4 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 4 Mar 2022 13:12:33 +0100 Subject: [PATCH 10/21] loops/basics completed --- src/loops/for-loop-basic.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/loops/for-loop-basic.js b/src/loops/for-loop-basic.js index 38a5c971..15b628b3 100644 --- a/src/loops/for-loop-basic.js +++ b/src/loops/for-loop-basic.js @@ -4,12 +4,29 @@ 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>=0; i--) { + countdown.push(i) +} + + // do not change below this line module.exports = { From 4c94c8fb0fbb709be78692c7003dcc1b97f68593 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 4 Mar 2022 14:07:22 +0100 Subject: [PATCH 11/21] for loops and arrays completed --- src/loops/for-loop-and-arrays.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/loops/for-loop-and-arrays.js b/src/loops/for-loop-and-arrays.js index 682995ec..8e19c72e 100644 --- a/src/loops/for-loop-and-arrays.js +++ b/src/loops/for-loop-and-arrays.js @@ -8,18 +8,39 @@ 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 = 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 = [] +for (i=0; i<=nums.length-1; i++){ + doubledNums.push(nums[i]*2); +} + // Use a for loop to set word equal to all the letters in the letters array word = '' +for (i=0; i=0; i--) { + numsReversed.push(nums[i]); +} + + // do not change below this line module.exports = { a: sum, From b5acf2ff30ad65eca4c012fcde505c5355e30ad8 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 4 Mar 2022 14:47:01 +0100 Subject: [PATCH 12/21] calling functions completed --- src/functions/calling-functions.js | 7 ++++--- src/functions/creating-functions.js | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/functions/calling-functions.js b/src/functions/calling-functions.js index f44038d6..01007994 100644 --- a/src/functions/calling-functions.js +++ b/src/functions/calling-functions.js @@ -19,13 +19,14 @@ 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 = { diff --git a/src/functions/creating-functions.js b/src/functions/creating-functions.js index 2d2ac5e6..e8ce8549 100644 --- a/src/functions/creating-functions.js +++ b/src/functions/creating-functions.js @@ -8,6 +8,10 @@ // // TODO: write code below +function incrementNumber (num) { + return num + 1 +} + // Define a function that takes any person's name and returns it with a smiley :)! // Remember to make the name capitalized! // From 6d563447066325672d26af3543e1cfc4ab38b976 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 4 Mar 2022 16:22:49 +0100 Subject: [PATCH 13/21] creating functions completed --- src/functions/creating-functions.js | 13 +++++++++---- { | 0 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 { diff --git a/src/functions/creating-functions.js b/src/functions/creating-functions.js index e8ce8549..ec5800a2 100644 --- a/src/functions/creating-functions.js +++ b/src/functions/creating-functions.js @@ -8,8 +8,8 @@ // // TODO: write code below -function incrementNumber (num) { - return num + 1 +function increment(number) { + return number + 1; } // Define a function that takes any person's name and returns it with a smiley :)! @@ -23,8 +23,13 @@ function incrementNumber (num) { // // TODO: write code below +function nameWithSmile (name) { + return "Hi, " + name[0].toUpperCase() + name.slice(1) + " :)" +} + + // 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: increment, // change undefined to be the name of the function you defined to increment a number (the first TODO) + b: nameWithSmile // change undefined to be the name of the function you defined to say hi (the second TODO) } diff --git a/{ b/{ new file mode 100644 index 00000000..e69de29b From 887953e64f8d0cb45a6cd805608dcac690d74104 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 4 Mar 2022 21:53:47 +0100 Subject: [PATCH 14/21] creating functions multiple arguments completed --- .../creating-functions-multiple-args.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/functions/creating-functions-multiple-args.js b/src/functions/creating-functions-multiple-args.js index a437ae8a..8034be05 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 + +function lowerUpper (lower, upper){ + let array = [] + for (let i=lower; i<=upper; i++) + array.push(i) + return array +} + // 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,14 @@ // // TODO: write code below +function myFunction (string, number) { + return string.toUpperCase() + number*"!" +} + + + // 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: lowerUpper, // change undefined to be the name of the function defined to create the range of numbers (the first todo) + b: myFunction // change undefined to be the name of the function defined to return the string with exclamations (the second todo) } From 993d5e92e341d9c15aabd4600bb9d97f36284428 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 5 Mar 2022 11:28:09 +0100 Subject: [PATCH 15/21] boolean conditions completed --- src/conditional-flow/boolean-conditions.js | 10 +++++- src/conditional-flow/multiple-conditions.js | 40 ++++++++++++++++++--- src/conditional-flow/numeric-conditions.js | 29 +++++++++++++-- 3 files changed, 70 insertions(+), 9 deletions(-) diff --git a/src/conditional-flow/boolean-conditions.js b/src/conditional-flow/boolean-conditions.js index 70b623d4..9c5d85c4 100644 --- a/src/conditional-flow/boolean-conditions.js +++ b/src/conditional-flow/boolean-conditions.js @@ -2,10 +2,18 @@ // "Well done, you passed!" if the value is true, or "Sorry, try again" // if the value is false. function getResult (didPass) { + if (didPass) { + return "Well done, you passed!" + } + else { + return "Sorry, try again" + } + +} // TODO: write code in this function body to pass the tests -} + module.exports = { a: getResult diff --git a/src/conditional-flow/multiple-conditions.js b/src/conditional-flow/multiple-conditions.js index 80420abf..458f2a3d 100644 --- a/src/conditional-flow/multiple-conditions.js +++ b/src/conditional-flow/multiple-conditions.js @@ -2,19 +2,31 @@ // than or equal to lower AND less than or equal to upper. // Implement this with a single condition. function isInRange (num, lower, upper) { - + if (num>=lower && num<=upper) { + return true; + } + else { + return false; + } +} // TODO: write code in this function body to pass the tests -} + // 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) { - + if (val1="Hello" || "Goodbye"){ + return true; + } + else { + return false; + } +} // TODO: write code in this function body to pass the tests -} + // This function should return a string that describes the provided age value. The // table below shows for each range of age values what string should be returned. @@ -28,10 +40,28 @@ function isHelloOrGoodbye (val1) { // 5-12 | Child // 13-19 | Teenager // 20+ | Adult + function getAgeDescription (age) { + if (age = 0) { + return "Baby" + } + else if (age >= 1 && age <= 4) { + return "Toddler" + } + else if (age > 5 && age < 13) { + return "Child" + } + else if (age > 12 && age < 20) { + return "Teenager" + } + else { + return "Adult" + } +} + // TODO: write code in this function body to pass the tests -} + module.exports = { a: isInRange, diff --git a/src/conditional-flow/numeric-conditions.js b/src/conditional-flow/numeric-conditions.js index 0f6656a5..987752e5 100644 --- a/src/conditional-flow/numeric-conditions.js +++ b/src/conditional-flow/numeric-conditions.js @@ -2,25 +2,48 @@ // This function should return true if there are no elements in the array, false otherwise function isArrayEmpty (array) { + if (array.length === 0) { + return true + } + else { + return false + } +} // TODO: write code in this function body to pass the tests -} + // This function should return true if num1 is greater than num2, false otherwise function isGreaterThan (num1, num2) { + if (num1 > num2) { + return true + } + else { + return false + } +} // TODO: write code in this function body to pass the tests -} + // This function should return the lowest number in the passed array function findLowest (nums) { + for (i=0; i=nums.length; i++){ + if (i<0){ + return i; + } + + } - // TODO: write code in this function body to pass the tests } + // TODO: write code in this function body to pass the tests + + + module.exports = { a: isArrayEmpty, b: isGreaterThan, From 5030f0a6c22da356e2a7fd457bac6b6095a78fba Mon Sep 17 00:00:00 2001 From: David Date: Sat, 5 Mar 2022 11:51:44 +0100 Subject: [PATCH 16/21] functions multiple args - i noticed the second part failed, now its completed --- src/functions/creating-functions-multiple-args.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/functions/creating-functions-multiple-args.js b/src/functions/creating-functions-multiple-args.js index 8034be05..7a3c43a8 100644 --- a/src/functions/creating-functions-multiple-args.js +++ b/src/functions/creating-functions-multiple-args.js @@ -30,10 +30,15 @@ function lowerUpper (lower, upper){ // // TODO: write code below -function myFunction (string, number) { - return string.toUpperCase() + number*"!" -} +function myFunction (word, number) { + const wordPart = word.toUpperCase() + const exclamationPart = [] + for (i = 0; i < number; i++) { + exclamationPart.push("!") + } +return wordPart + exclamationPart.join("") +} // change the exported value to be the name of the function you defined From e0613a472ec1da8af3afd8f5bc81c06b5ba774d0 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 5 Mar 2022 13:11:16 +0100 Subject: [PATCH 17/21] numeric conditions complete --- src/conditional-flow/numeric-conditions.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/conditional-flow/numeric-conditions.js b/src/conditional-flow/numeric-conditions.js index 987752e5..ecd4c216 100644 --- a/src/conditional-flow/numeric-conditions.js +++ b/src/conditional-flow/numeric-conditions.js @@ -29,16 +29,19 @@ function isGreaterThan (num1, num2) { // This function should return the lowest number in the passed array + + function findLowest (nums) { - for (i=0; i=nums.length; i++){ - if (i<0){ - return i; + let smallest = nums[0] + for (let i = 1; i < nums.length; i++) { + if (nums[i] < smallest) { + smallest = nums[i] } - - } + } + return smallest +} -} // TODO: write code in this function body to pass the tests From c7ecd3c174793e49f9b7cb8e1ffe2a578e63e6c1 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 6 Mar 2022 00:41:01 +0100 Subject: [PATCH 18/21] multiple conditions completed --- src/conditional-flow/multiple-conditions.js | 15 ++--- src/conditional-flow/string-conditions.js | 71 +++++++++++++++++++-- 2 files changed, 73 insertions(+), 13 deletions(-) diff --git a/src/conditional-flow/multiple-conditions.js b/src/conditional-flow/multiple-conditions.js index 458f2a3d..4aecef07 100644 --- a/src/conditional-flow/multiple-conditions.js +++ b/src/conditional-flow/multiple-conditions.js @@ -17,12 +17,11 @@ function isInRange (num, lower, upper) { // to "Hello" or "Goodbye". Implement this with a single // if statement. function isHelloOrGoodbye (val1) { - if (val1="Hello" || "Goodbye"){ - return true; - } - else { - return false; - } + if (val1 === "Hello" || val1 === "Goodbye") { + return true + } + return false + } // TODO: write code in this function body to pass the tests @@ -42,13 +41,13 @@ function isHelloOrGoodbye (val1) { // 20+ | Adult function getAgeDescription (age) { - if (age = 0) { + if (age === 0) { return "Baby" } else if (age >= 1 && age <= 4) { return "Toddler" } - else if (age > 5 && age < 13) { + else if (age >= 5 && age <=12) { return "Child" } else if (age > 12 && age < 20) { diff --git a/src/conditional-flow/string-conditions.js b/src/conditional-flow/string-conditions.js index d91bfaf0..3e24e215 100644 --- a/src/conditional-flow/string-conditions.js +++ b/src/conditional-flow/string-conditions.js @@ -1,20 +1,37 @@ // This function should return true if the passed string is equal to "Hello" function isHello (val1) { + if (val1 === "Hello"){ + return true + } + if (val1 !== "Hello") { + return false + } +} // TODO: write code in this function body to pass the tests -} // This function should return true if the passed string is not equal to "Hello" function isNotHello (val1) { - + if (val1 !== "Hello") { + return true + } + if (val1 === "Hello") { + return false + } +} // TODO: write code in this function body to pass the tests -} // This function should return true if the string val1 is is longer // than string val2 function isLongerThan (val1, val2) { + if (val1.length > val2.length) { + return true + } + else { + return false + } // TODO: write code in this function body to pass the tests @@ -24,10 +41,18 @@ function isLongerThan (val1, val2) { // argument has an odd number of vowels function hasOddNumberVowels (val1) { - + const vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"] + const vowelsInString = [] + for (i=0; i Date: Mon, 7 Mar 2022 17:53:47 +0100 Subject: [PATCH 19/21] string conditions completed --- src/conditional-flow/string-conditions.js | 96 +++++++++++++---------- src/loops/for-loop-basic.js | 1 + 2 files changed, 55 insertions(+), 42 deletions(-) diff --git a/src/conditional-flow/string-conditions.js b/src/conditional-flow/string-conditions.js index 3e24e215..d5faa47b 100644 --- a/src/conditional-flow/string-conditions.js +++ b/src/conditional-flow/string-conditions.js @@ -25,6 +25,7 @@ function isNotHello (val1) { // This function should return true if the string val1 is is longer // than string val2 + function isLongerThan (val1, val2) { if (val1.length > val2.length) { return true @@ -33,6 +34,7 @@ function isLongerThan (val1, val2) { return false } + // TODO: write code in this function body to pass the tests } @@ -41,15 +43,21 @@ function isLongerThan (val1, val2) { // argument has an odd number of vowels function hasOddNumberVowels (val1) { - const vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"] - const vowelsInString = [] - for (i=0; i=0; i--) { countdown.push(i) + console.log(countdown); } From 983421921506ed91c95b23ec8184bdef54826065 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 8 Mar 2022 12:28:26 +0100 Subject: [PATCH 20/21] objects correncted --- src/data-types/objects/creating-objects.js | 34 ++++++++++++---------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/data-types/objects/creating-objects.js b/src/data-types/objects/creating-objects.js index 0abf57a0..656fce40 100644 --- a/src/data-types/objects/creating-objects.js +++ b/src/data-types/objects/creating-objects.js @@ -1,7 +1,24 @@ // 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 +// Person should be an object with the name "Jane" +//Person should be an object with the age 32' +//Computer should be an object with the form "laptop" +//Computer.specs should be an object with a memory "16GB" and storage "1TB" + + +const person = { + name: "Jane", + age: 32 +} + +const computer = { + form: "laptop", + specs: { + memory: "16GB", + storage: "1TB" + } +} + // Do not edit this exported object module.exports = { @@ -9,19 +26,6 @@ module.exports = { computer: computer } -// Person should be an object with the name "Jane" -person.name = "Jane" - -//Person should be an object with the age 32' -person.age = 32 - -//Computer should be an object with the form "laptop" -computer.form = "laptop" -//Computer.specs should be an object with a memory "16GB" and storage "1TB" -computer.specs { - memory: "16GB", - storage: "1TB" -} \ No newline at end of file From 20da268e4a1d077bf6e97161b030dece555cecc8 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 8 Mar 2022 12:33:20 +0100 Subject: [PATCH 21/21] demo completed --- src/demo/demo.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/demo/demo.js b/src/demo/demo.js index 9201bd8a..c6f97712 100644 --- a/src/demo/demo.js +++ b/src/demo/demo.js @@ -4,11 +4,11 @@ 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 = numOne + numTwo // Set this variable to numOne plus numTwo // do not edit this section module.exports = {