From e86521b9eda3dec3e59021030d721be8a4a4e526 Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Thu, 3 Mar 2022 11:35:05 +0000 Subject: [PATCH 01/18] Variables: assignment.js test pass --- 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 6aee1f7d3d10bb37c010d96ac9bbf04ccaf70752 Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Thu, 3 Mar 2022 11:42:45 +0000 Subject: [PATCH 02/18] Variables: declaration.js test pass --- src/variables/declaration.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/variables/declaration.js b/src/variables/declaration.js index 8afaa55b..c54265b1 100644 --- a/src/variables/declaration.js +++ b/src/variables/declaration.js @@ -3,6 +3,10 @@ // // 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) {} From e4faed39422aad8c0f4789922ff1a7dcd88347e0 Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Thu, 3 Mar 2022 16:31:00 +0000 Subject: [PATCH 03/18] Data-types: numbers.js test pass --- src/data-types/example.js | 3 +++ src/data-types/numbers.js | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/data-types/example.js b/src/data-types/example.js index 87240301..efe38130 100644 --- a/src/data-types/example.js +++ b/src/data-types/example.js @@ -12,6 +12,8 @@ const upperCaseHello = hello.toUpperCase() const secondCharacterOfDog = animal.charAt(1) const howManyVowels = vowels.length + + // TODO: Update the code below using numeric operators so that the tests // pass const numOneMultipliedByNumTwo = numOne * numTwo @@ -23,3 +25,4 @@ module.exports = { c: howManyVowels, d: numOneMultipliedByNumTwo } + diff --git a/src/data-types/numbers.js b/src/data-types/numbers.js index 01dd70de..5433f1b6 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 = 24 // Set this variable to numThree multiplied by numTwo -const numThreeTimesNumTwo = NaN +const numThreeTimesNumTwo = 512 // Set this variable to numThree divided by numOne -const numThreeDividedByNumOne = NaN +const numThreeDividedByNumOne = 4 // Set this variable to numThree minus numOne -const numThreeMinusNumOne = NaN +const numThreeMinusNumOne = 24 // Set this variable to the sum of numOne, numTwo and numThree -const sum = NaN +const sum = 56 // Set this variable to the sum of (numOne, numTwo, numThree) divided by numOne -const numBytes = NaN +const numBytes = 7 // do not edit the exported object. module.exports = { From 4dcf0fc81e9bd49e4fd86c0996aa4b48819b0669 Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Thu, 3 Mar 2022 17:23:10 +0000 Subject: [PATCH 04/18] Data-types: strings.js test pass --- 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 a40a15ff39a26045d3c7de605dec4ab4a43f0e58 Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Fri, 4 Mar 2022 11:26:06 +0000 Subject: [PATCH 05/18] Data-types : --- 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..4dbc3403 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 = 'Delhi' // Set firstCity to the 1st element in the cities array -const firstCity = '' +const firstCity = 'London' // 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 ffacea37c60a1b66c2e235f6ce837f305155b8ce Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Fri, 4 Mar 2022 12:21:04 +0000 Subject: [PATCH 06/18] Data-types: adding-removing-elements.js test pass --- 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..80fa3d2e 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 c8b392dc4697565c19cbb462c6c39781cee2a780 Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Fri, 4 Mar 2022 14:49:12 +0000 Subject: [PATCH 07/18] Data-types: Object-keys.js test pass --- src/data-types/objects/object-keys.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data-types/objects/object-keys.js b/src/data-types/objects/object-keys.js index 4999e940..522539e3 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 = { From 88f25cb64dd58058ab12f83d6664346e2abccdec Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Fri, 4 Mar 2022 15:25:58 +0000 Subject: [PATCH 08/18] Data-types: Object-and-arrays.js test pass --- 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..eb28bd57 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 9a593ce16d2ed752dd0ea0c0549ac1f647614f66 Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Sun, 6 Mar 2022 23:43:36 +0000 Subject: [PATCH 09/18] functions: calling-functions test pass --- 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..f5d15e00 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 = sayHello('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 58e146865022fa8f99b67f2628e47bc821f479cf Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Sun, 6 Mar 2022 23:45:42 +0000 Subject: [PATCH 10/18] functions: creating-functions-multiple-args.js test pass --- src/functions/creating-functions-multiple-args.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/functions/creating-functions-multiple-args.js b/src/functions/creating-functions-multiple-args.js index a437ae8a..5bee9a2c 100644 --- a/src/functions/creating-functions-multiple-args.js +++ b/src/functions/creating-functions-multiple-args.js @@ -10,6 +10,13 @@ // // TODO: write code below +const createArray = (lower, upper) => { + const output = [] + for (let i = lower; i <= upper; i++) { + output.push(i) + } return output +} + // 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,6 +29,14 @@ // // TODO: write code below +const toUpperCase = (word, num) => { + const exclamationMark = [] + for (i = 0; i < num; i++) { + exclamationMark.push('!') + } + return word.toUpperCase() + exclamationMark.join('') +} + // 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) From 30f5c4e8301bd07fcf95bd5d8db5b03baf34dd01 Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Sun, 6 Mar 2022 23:46:59 +0000 Subject: [PATCH 11/18] functions: creating-functions.js test pass --- src/functions/creating-functions.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/functions/creating-functions.js b/src/functions/creating-functions.js index 2d2ac5e6..78ce6fc6 100644 --- a/src/functions/creating-functions.js +++ b/src/functions/creating-functions.js @@ -8,6 +8,10 @@ // // TODO: write code below +const plusOne = 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! // @@ -19,6 +23,11 @@ // // TODO: write code below +const smile = name => { + const capitalizedName = name.charAt(0).toUpperCase() + name.slice(1) + return 'Hi, ' + capitalizedName + ' :)' +} + // 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) From b35686ddc8a5596f3274dcbbf0093c2b61d4fbc1 Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Mon, 7 Mar 2022 13:10:19 +0000 Subject: [PATCH 12/18] loops: for-loops-basic.js test pass --- src/loops/for-loop-basic.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/loops/for-loop-basic.js b/src/loops/for-loop-basic.js index 38a5c971..27da13f9 100644 --- a/src/loops/for-loop-basic.js +++ b/src/loops/for-loop-basic.js @@ -5,12 +5,28 @@ const countdown = [] // TODO: Write a for loop that adds the numbers 0 to 3 to the numsZeroToThree array +for (let i = 0; i <= 3; i++) { + numsZeroToThree.push(i) +} + // TODO: Write a for loop that adds the numbers 5 to 10 to the numsFiveToTen array +for (let j = 5; j <= 10; j++) { + numsFiveToTen.push(j) +} + // TODO: Write a for loop that adds all the even numbers between 0 and 6 (0, 2, 4, 6) to evenNums +for (let k = 0; k <= 6; k += 2) { + evenNums.push(k) +} + // TODO: Write a for loop that adds the numbers 3 to 0 (in that order) to the countdown array +for (let l = 3; l >= 0; l--) { + countdown.push(l) +} + // do not change below this line module.exports = { a: numsZeroToThree, From 5dd1856b788878b0a6a26d0262e3dec93364a278 Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Mon, 7 Mar 2022 20:19:44 +0000 Subject: [PATCH 13/18] loops: for-loop-and-arrays.js partially test pass --- src/loops/for-loop-and-arrays.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/loops/for-loop-and-arrays.js b/src/loops/for-loop-and-arrays.js index 682995ec..163e1120 100644 --- a/src/loops/for-loop-and-arrays.js +++ b/src/loops/for-loop-and-arrays.js @@ -6,13 +6,26 @@ let word = '' // TODO: Add code below this line to make the tests pass // 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 = [] + +const doubledNums = (arr) => { + const doubledArr = [] + for (let j = 0; j < arr.length; j++) { + doubledArr.push(arr[j] * 2) + } + return doubledArr +} // Use a for loop to set word equal to all the letters in the letters array -word = '' + +for (let k = 0; k < letters.length; k++) { + word = word + letters[k] +} // Use a for loop to populate everySecondNum with every second number from the nums array const everySecondNum = [] From fc4418d612e83a9047513cc81e1e54d7f1dda809 Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Tue, 8 Mar 2022 17:14:17 +0000 Subject: [PATCH 14/18] loops: for-loop-and-arrays.js test pass --- src/conditional-flow/boolean-conditions.js | 5 ++++- src/loops/for-loop-and-arrays.js | 17 +++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/conditional-flow/boolean-conditions.js b/src/conditional-flow/boolean-conditions.js index 70b623d4..32442bca 100644 --- a/src/conditional-flow/boolean-conditions.js +++ b/src/conditional-flow/boolean-conditions.js @@ -2,9 +2,12 @@ // "Well done, you passed!" if the value is true, or "Sorry, try again" // if the value is false. function getResult (didPass) { - // TODO: write code in this function body to pass the tests + if (didPass) { + return "Well done, you passed!" + } + return "Sorry, try again" } module.exports = { diff --git a/src/loops/for-loop-and-arrays.js b/src/loops/for-loop-and-arrays.js index 163e1120..c1826ca0 100644 --- a/src/loops/for-loop-and-arrays.js +++ b/src/loops/for-loop-and-arrays.js @@ -7,18 +7,17 @@ let word = '' // Use a for loop to set the sum variable to the sum of all the values in nums +sums = 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 = (arr) => { - const doubledArr = [] - for (let j = 0; j < arr.length; j++) { - doubledArr.push(arr[j] * 2) - } - return doubledArr +const doubledNums = [] +for (let j = 0; j < nums.length; j++) { + + doubledNums.push(nums[j]*2) } // Use a for loop to set word equal to all the letters in the letters array @@ -29,9 +28,15 @@ for (let k = 0; k < letters.length; k++) { // Use a for loop to populate everySecondNum with every second number from the nums array const everySecondNum = [] +for (let l = 1; l < nums.length; l += 2) { + everySecondNum.push(nums[l]) +} // Use a for loop to populate numsReversed with the numbers from nums in reverse order const numsReversed = [] +for (let m = 0; m < nums.length; m++) { + numsReversed.unshift(nums[m]) +} // do not change below this line module.exports = { From 899e0ca685db7623ae53e61c68d2aa09103323d2 Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Tue, 8 Mar 2022 17:35:07 +0000 Subject: [PATCH 15/18] conditional-flow: boolean-conditions.js test pass complete --- src/conditional-flow/boolean-conditions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conditional-flow/boolean-conditions.js b/src/conditional-flow/boolean-conditions.js index 32442bca..876821c0 100644 --- a/src/conditional-flow/boolean-conditions.js +++ b/src/conditional-flow/boolean-conditions.js @@ -9,7 +9,7 @@ function getResult (didPass) { } return "Sorry, try again" } - +// if well done phrase is not displayed then it assume you did not pass and display try again module.exports = { a: getResult } From 229a47ba5f6a5a9c9e0f18a4cc712a81d9918f1b Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Wed, 9 Mar 2022 00:01:02 +0000 Subject: [PATCH 16/18] conditional flow: multiple-conditions.js test pass --- src/conditional-flow/multiple-conditions.js | 26 ++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/conditional-flow/multiple-conditions.js b/src/conditional-flow/multiple-conditions.js index 80420abf..9875974d 100644 --- a/src/conditional-flow/multiple-conditions.js +++ b/src/conditional-flow/multiple-conditions.js @@ -2,18 +2,21 @@ // than or equal to lower AND less than or equal to upper. // Implement this with a single condition. function isInRange (num, lower, upper) { - // TODO: write code in this function body to pass the tests + 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) { - // TODO: write code in this function body to pass the tests + if (val1 === 'Hello' || val1 === 'Goodbye') { + return true + } + return false } // This function should return a string that describes the provided age value. The @@ -29,8 +32,25 @@ function isHelloOrGoodbye (val1) { // 13-19 | Teenager // 20+ | Adult function getAgeDescription (age) { - // TODO: write code in this function body to pass the tests + + let description = '' + if (age === 0) { + description = 'Baby' + } + else if (age < 5) { + description = 'Toddler' + } + else if (age < 13) { + description = 'Child' + } + else if (age < 20) { + description = 'Teenager' + } + else { + description = 'Adult' + } + return description } module.exports = { From af162249d50e9b9eab7ec8be8087661f016dbd80 Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Wed, 9 Mar 2022 00:03:33 +0000 Subject: [PATCH 17/18] conditional-flow: numeric-conditions.js test pass --- src/conditional-flow/numeric-conditions.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/conditional-flow/numeric-conditions.js b/src/conditional-flow/numeric-conditions.js index 0f6656a5..4702ce1e 100644 --- a/src/conditional-flow/numeric-conditions.js +++ b/src/conditional-flow/numeric-conditions.js @@ -2,23 +2,29 @@ // This function should return true if there are no elements in the array, false otherwise function isArrayEmpty (array) { - // TODO: write code in this function body to pass the tests + return (array.length === 0) } // 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) } // 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 + let smallest = nums[0] + for (let i = 1; i < nums.length; i++) { + if (nums[i] < smallest) { + smallest = nums[i] + } + } + return smallest } module.exports = { From 25311074db6ee0d490a5c1a0b1059248f566df4b Mon Sep 17 00:00:00 2001 From: UnknownCreator1 <90321114+UnknownCreator1@users.noreply.github.com> Date: Wed, 9 Mar 2022 15:09:35 +0000 Subject: [PATCH 18/18] conditional-flow: string-conditions.js test pass --- src/conditional-flow/string-conditions.js | 75 ++++++++++++++++++++--- 1 file changed, 66 insertions(+), 9 deletions(-) diff --git a/src/conditional-flow/string-conditions.js b/src/conditional-flow/string-conditions.js index d91bfaf0..16e920a9 100644 --- a/src/conditional-flow/string-conditions.js +++ b/src/conditional-flow/string-conditions.js @@ -1,32 +1,40 @@ // This function should return true if the passed string is equal to "Hello" function isHello (val1) { - // TODO: write code in this function body to pass the tests - + // return (val1 === 'Hello') + if (val1 === "Hello") return true; + return false; } // This function should return true if the passed string is not equal to "Hello" function isNotHello (val1) { - // TODO: write code in this function body to pass the tests - + // return (val1 !== 'Hello') + if (val1 !== "Hello") return true; + return false; } // This function should return true if the string val1 is is longer // than string val2 function isLongerThan (val1, val2) { - // TODO: write code in this function body to pass the tests - + if (val1.length > val2.length) return true; + return false; } // This function should return true if the string passed in the function's first // argument has an odd number of vowels function hasOddNumberVowels (val1) { - // TODO: write code in this function body to pass the tests - + const VOWELS = ['a', 'e', 'i', 'o', 'u'] + let total = 0 + for (let i = 0; i < val1.length; i++) { + if (VOWELS.includes(val1[i].toLowerCase())) { + total++ + } + } + return Boolean(total % 2) } // this function should return the middle character of a string if it has an odd number @@ -36,6 +44,16 @@ function hasOddNumberVowels (val1) { function getMiddleLetter (val1) { // TODO: write code in this function body to pass the tests + let mid = Math.round(val1.length / 2) + let chars = "" + if (val1.length % 2 === 0) { + chars += val1[mid - 1] + chars += val1[mid] + } + else { + chars += val1[mid - 1] + } + return chars } // This function should return the name of the season for the provided @@ -48,8 +66,47 @@ function getMiddleLetter (val1) { // Autumn - September to November // Winter - December to February function seasonForMonth (monthName) { - // TODO: write code in this function body to pass the tests + switch (monthName) { + case (monthName = "January"): + return "Winter"; + break; + case (monthName = "February"): + return "Winter"; + break; + case (monthName = "December"): + return "Winter"; + break; + case (monthName = "March"): + return "Spring"; + break; + case (monthName = "April"): + return "Spring"; + break; + case (monthName = "May"): + return "Spring"; + break; + case (monthName = "June"): + return "Summer"; + break; + case (monthName = "July"): + return "Summer"; + break; + case (monthName = "August"): + return "Summer"; + break; + case (monthName = "September"): + return "Autumn"; + break; + case (monthName = "October"): + return "Autumn"; + break; + case (monthName = "November"): + return "Autumn"; + break; + default: + return ""; + } } module.exports = {