From 519d89bc50052ee9c1b976af9b145b5897a49c88 Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Thu, 3 Mar 2022 11:24:45 +0000 Subject: [PATCH 01/16] EX: Variables assignment completed --- package-lock.json | 1 + src/variables/assignment.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) 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..4cd58664 100644 --- a/src/variables/assignment.js +++ b/src/variables/assignment.js @@ -4,8 +4,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 65b321b7c918b965ef2f9e2bee9b75e1cd2e5b47 Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Thu, 3 Mar 2022 11:37:32 +0000 Subject: [PATCH 02/16] EX: Declaration assignment completed --- src/variables/declaration.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/variables/declaration.js b/src/variables/declaration.js index 8afaa55b..c1b4d453 100644 --- a/src/variables/declaration.js +++ b/src/variables/declaration.js @@ -2,7 +2,9 @@ // // // TODO: Declare the variables firstName and age so that the tests pass +let firstName = "Jane" +const age = 35 // do not edit below this line let firstNameExport = '' try { firstNameExport = firstName } catch (e) {} From 1088caeedde617a290e439a6ce05faa2567c08e3 Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Thu, 3 Mar 2022 11:48:29 +0000 Subject: [PATCH 03/16] EX: 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 1ac35dea9fd61d738842ea11de68d8db5ae299be Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Thu, 3 Mar 2022 12:06:15 +0000 Subject: [PATCH 04/16] EX: Data-type 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..fcf84f13 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 = "Jane" + " " + "Smith" // Set this variable to the 10th character of the alphabet variable -const tenthCharacterOfAlphabet = null +const tenthCharacterOfAlphabet = "J" // Set this variable by calling a method on the alphabet variable to transform it to lower case -const lowerCaseAlphabet = null +const lowerCaseAlphabet = "abcdefghijklmnopqrstuvwxyz" // Set this variable by using a property on the alphabet variable to get it's length -const numberOfLettersInAlphabet = null +const numberOfLettersInAlphabet = 26 // do not edit the exported object. module.exports = { From 3685b8d108008a2a66db6dbe1e6f31dffba285d4 Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Thu, 3 Mar 2022 12:24:03 +0000 Subject: [PATCH 05/16] EX: data-types accessing elements completed --- 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..df656876 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 = 5 // Do not edit this exported object module.exports = { From 0d9b57c87b5ddf49104df8b845e0742566a61013 Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Thu, 3 Mar 2022 16:19:06 +0000 Subject: [PATCH 06/16] EX:Adding-removing-elemetns completed --- 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..98c05963 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("Red") // Use an array method to remove the last item from keys -keys +keys.pop("y") // 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("Pear") // Do not edit this exported object module.exports = { From 41f3c50efdaaaf3569269ee4a113f0bdfd8036ec Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Thu, 3 Mar 2022 17:38:44 +0000 Subject: [PATCH 07/16] EX: Object keys completed --- src/data-types/arrays/adding-removing-elements.js | 4 ++-- src/data-types/objects/object-keys.js | 14 ++++++++++++-- src/data-types/strings.js | 6 +++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/data-types/arrays/adding-removing-elements.js b/src/data-types/arrays/adding-removing-elements.js index 98c05963..e8f6256b 100644 --- a/src/data-types/arrays/adding-removing-elements.js +++ b/src/data-types/arrays/adding-removing-elements.js @@ -22,13 +22,13 @@ cities.unshift("Rio") colours.shift("Red") // Use an array method to remove the last item from keys -keys.pop("y") +keys.pop() // Use an array method to remove 'Jordon' from the countries array 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.pop("Pear") +const pear = fruits.pop() // Do not edit this exported object module.exports = { diff --git a/src/data-types/objects/object-keys.js b/src/data-types/objects/object-keys.js index 4999e940..b185f644 100644 --- a/src/data-types/objects/object-keys.js +++ b/src/data-types/objects/object-keys.js @@ -17,10 +17,20 @@ const isbn13 = '978-0132350884' // as well as modify some of the existing code // Set this to the book name -const name = '' +const name = 'Clean Code' // Set this to the isbn 10 value -const isbn10 = '' +const isbn10 = '9780132350884' + +book["category"] = "Programming" + +book["pages"] = 464; + +book.isbn["isbn13"] = '978-0132350884' + +delete book.dimensions; + +delete book.isbn.asin; // Do not edit this exported object module.exports = { diff --git a/src/data-types/strings.js b/src/data-types/strings.js index fcf84f13..cae85d68 100644 --- a/src/data-types/strings.js +++ b/src/data-types/strings.js @@ -9,13 +9,13 @@ const secondName = 'Smith' const fullName = "Jane" + " " + "Smith" // Set this variable to the 10th character of the alphabet variable -const tenthCharacterOfAlphabet = "J" +const tenthCharacterOfAlphabet = alphabet[9] // Set this variable by calling a method on the alphabet variable to transform it to lower case -const lowerCaseAlphabet = "abcdefghijklmnopqrstuvwxyz" +const lowerCaseAlphabet = alphabet.toLowerCase() // Set this variable by using a property on the alphabet variable to get it's length -const numberOfLettersInAlphabet = 26 +const numberOfLettersInAlphabet = alphabet.length // do not edit the exported object. module.exports = { From f933dc0a7d96127a9cbdbbd83f7c9b664279d6cd Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Thu, 3 Mar 2022 17:52:17 +0000 Subject: [PATCH 08/16] EX: Creating-Object completed --- 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..9bb0f303 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 f1db7e2d02fb8af4cb7c1b6c2832d97ea6679c4b Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Mon, 7 Mar 2022 09:44:00 +0000 Subject: [PATCH 09/16] Objects and arrays completed --- src/data-types/arrays/accessing-elements.js | 8 ++++---- src/data-types/objects/object-keys.js | 4 ++-- src/data-types/objects/objects-and-arrays.js | 15 +++++++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/data-types/arrays/accessing-elements.js b/src/data-types/arrays/accessing-elements.js index df656876..b9a1bc24 100644 --- a/src/data-types/arrays/accessing-elements.js +++ b/src/data-types/arrays/accessing-elements.js @@ -7,15 +7,15 @@ const cities = ['London', 'Shanghai', 'New York', 'Delhi', 'Kuala Lumpur'] const names = ["Bob", "Jane", "Joanna"] // Set fourthCity to the 4th element in the cities array -const fourthCity = 'Delhi' +const fourthCity = cities[3] // Set firstCity to the 1st element in the cities array -const firstCity = 'London' +const firstCity = cities[0] // Set lengthOfCitiesArray to the length of the cities array -const lengthOfCitiesArray = 5 +const lengthOfCitiesArray = cities.length -// Do not edit this exported object +// Do not edit this exported object module.exports = { a: names, b: fourthCity, diff --git a/src/data-types/objects/object-keys.js b/src/data-types/objects/object-keys.js index b185f644..ba01ed34 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 = 'Clean Code' +const name = book.name // Set this to the isbn 10 value -const isbn10 = '9780132350884' +const isbn10 = book.isbn.isbn10 book["category"] = "Programming" diff --git a/src/data-types/objects/objects-and-arrays.js b/src/data-types/objects/objects-and-arrays.js index e4819467..584a5664 100644 --- a/src/data-types/objects/objects-and-arrays.js +++ b/src/data-types/objects/objects-and-arrays.js @@ -1,3 +1,5 @@ +const { b } = require("../arrays/adding-removing-elements") + // do not modify this code const basket = { items: [ @@ -22,10 +24,19 @@ 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] + + basket.items[0].price = 2 + +basket.items.push({ + name: "Oranges", + price: 0.75, + quantity: 4 +}) + // Do not edit this exported object module.exports = { From 641e320349e7c558afdc2039b66448a3ccc45187 Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Mon, 7 Mar 2022 14:30:31 +0000 Subject: [PATCH 10/16] for loop basic completed --- src/loops/for-loop-basic.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/loops/for-loop-basic.js b/src/loops/for-loop-basic.js index 38a5c971..187c1c77 100644 --- a/src/loops/for-loop-basic.js +++ b/src/loops/for-loop-basic.js @@ -5,11 +5,24 @@ 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 -// TODO: Write a for loop that adds all the even numbers between 0 and 6 (0, 2, 4, 6) to evenNums +for (let i = 5; i <= 10; 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 <= 6; 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 721dea1a4221fb2c9e0c0bb937607b6de5987af3 Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Mon, 7 Mar 2022 16:17:07 +0000 Subject: [PATCH 11/16] EX: For loops and arrays completed --- 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..5522adda 100644 --- a/src/loops/for-loop-and-arrays.js +++ b/src/loops/for-loop-and-arrays.js @@ -7,18 +7,31 @@ 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 (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 = 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){ + everySecondNum.push(nums[i]) +} // Use a for loop to populate numsReversed with the numbers from nums in reverse order const numsReversed = [] +for (i = nums.length -1; i >= 0; i--){ + numsReversed.push(nums[i]); +} + // do not change below this line module.exports = { From ddee5a74f72d74280603f053cad0ecaf137fb1b7 Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Tue, 8 Mar 2022 11:56:36 +0000 Subject: [PATCH 12/16] Calling functions completed --- 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..308776e2 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 06f4d25b2181d17b57e2bf3cad670eda788fd2bc Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Tue, 8 Mar 2022 13:21:16 +0000 Subject: [PATCH 13/16] Creating Functions completed --- src/functions/creating-functions.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/functions/creating-functions.js b/src/functions/creating-functions.js index 2d2ac5e6..187f96bb 100644 --- a/src/functions/creating-functions.js +++ b/src/functions/creating-functions.js @@ -7,7 +7,9 @@ // 2 | 3 // // TODO: write code below - +function incrementsNumber(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! // @@ -18,9 +20,13 @@ // Aiyana | Hi, Aiyana :) // // TODO: write code below +function Smiley(name){ + + return "Hi, " + name.charAt(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: incrementsNumber, // change undefined to be the name of the function you defined to increment a number (the first TODO) + b: Smiley // change undefined to be the name of the function you defined to say hi (the second TODO) } From 96f7ead4c4df9b42be74aa64f0ad10f9bd802ea8 Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Wed, 9 Mar 2022 12:07:55 +0000 Subject: [PATCH 14/16] Ex: Creating functions multiple args completed --- src/data-types/numbers.js | 3 +-- .../creating-functions-multiple-args.js | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/data-types/numbers.js b/src/data-types/numbers.js index 8ec2eaa6..4d1c9579 100644 --- a/src/data-types/numbers.js +++ b/src/data-types/numbers.js @@ -21,8 +21,7 @@ const numThreeMinusNumOne = numThree - numOne const sum = numOne + numTwo + numThree // Set this variable to the sum of (numOne, numTwo, numThree) divided by numOne -const numBytes = (numOne + numTwo + numThree) / numOne - +const numBytes = (numOne + numTwo + numThree) / numOne // do not edit the exported object. module.exports = { a: numOnePlusNumTwo, diff --git a/src/functions/creating-functions-multiple-args.js b/src/functions/creating-functions-multiple-args.js index a437ae8a..ab6f7822 100644 --- a/src/functions/creating-functions-multiple-args.js +++ b/src/functions/creating-functions-multiple-args.js @@ -9,7 +9,15 @@ // -1, 1 | [-1, 0, 1] // // TODO: write code below +function range (lower,upper){ + const outputArray = []; + + for (let i = lower; i <= upper; i++){ + outputArray.push(i) + } + return outputArray; +} // 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 @@ -21,9 +29,22 @@ // error, 10 | ERROR!!!!!!!!!! // // TODO: write code below +function StringAndNumber(string,number){ +let outputmessage = string.toUpperCase() +//Upper case the string complete + let exclamation = "" +// Implementing the exclamation mark + for(let i = 0; i < number; i++){ + exclamation = exclamation + "!" + } + //Storing the result into outputmessage + outputmessage = outputmessage + exclamation + + return outputmessage; +} // 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: range, // change undefined to be the name of the function defined to create the range of numbers (the first todo) + b: StringAndNumber // change undefined to be the name of the function defined to return the string with exclamations (the second todo) } From 0d6c433f6c46ef509a02d0529de75a1c87ac4034 Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Wed, 9 Mar 2022 15:39:37 +0000 Subject: [PATCH 15/16] Creating functions multiple args completed --- src/functions/creating-functions-multiple-args.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/creating-functions-multiple-args.js b/src/functions/creating-functions-multiple-args.js index ab6f7822..dc4535db 100644 --- a/src/functions/creating-functions-multiple-args.js +++ b/src/functions/creating-functions-multiple-args.js @@ -42,7 +42,7 @@ let outputmessage = string.toUpperCase() return outputmessage; } - +{} // change the exported value to be the name of the function you defined module.exports = { a: range, // change undefined to be the name of the function defined to create the range of numbers (the first todo) From 87bd4d27d5fc72f1313728901ee92ec7bfd692cb Mon Sep 17 00:00:00 2001 From: SeanRichhh Date: Mon, 20 Jun 2022 16:43:02 +0100 Subject: [PATCH 16/16] completed --- src/conditional-flow/boolean-conditions.js | 6 +- src/conditional-flow/multiple-conditions.js | 20 +++++- src/conditional-flow/numeric-conditions.js | 14 +++- src/conditional-flow/string-conditions.js | 75 +++++++++++++++++++-- src/data-types/strings.js | 2 +- 5 files changed, 105 insertions(+), 12 deletions(-) diff --git a/src/conditional-flow/boolean-conditions.js b/src/conditional-flow/boolean-conditions.js index 70b623d4..194b6d31 100644 --- a/src/conditional-flow/boolean-conditions.js +++ b/src/conditional-flow/boolean-conditions.js @@ -4,7 +4,11 @@ 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" + } } module.exports = { diff --git a/src/conditional-flow/multiple-conditions.js b/src/conditional-flow/multiple-conditions.js index 80420abf..9368cac8 100644 --- a/src/conditional-flow/multiple-conditions.js +++ b/src/conditional-flow/multiple-conditions.js @@ -4,8 +4,8 @@ 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 @@ -13,7 +13,10 @@ function isInRange (num, lower, upper) { 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 +34,17 @@ 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 = { diff --git a/src/conditional-flow/numeric-conditions.js b/src/conditional-flow/numeric-conditions.js index 0f6656a5..65328c6c 100644 --- a/src/conditional-flow/numeric-conditions.js +++ b/src/conditional-flow/numeric-conditions.js @@ -4,21 +4,31 @@ function isArrayEmpty (array) { // TODO: write code in this function body to pass the tests - + if(array.length === 0){ + return true + }else{ + return 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 - + if(num1 > num2){ + return true + }else{ + return 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 + smallestNum = Math.min(...nums) + return smallestNum } module.exports = { diff --git a/src/conditional-flow/string-conditions.js b/src/conditional-flow/string-conditions.js index d91bfaf0..a3a8c3a0 100644 --- a/src/conditional-flow/string-conditions.js +++ b/src/conditional-flow/string-conditions.js @@ -2,14 +2,22 @@ function isHello (val1) { // TODO: write code in this function body to pass the tests - + if(val1 === "Hello"){ + return true + }else{ + 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 - + if(val1 !== "Hello"){ + return true + }else{ + return false + } } // This function should return true if the string val1 is is longer @@ -17,7 +25,11 @@ function isNotHello (val1) { function isLongerThan (val1, val2) { // TODO: write code in this function body to pass the tests - + if(val1.length > val2.length){ + return true + }else{ + return false + } } // This function should return true if the string passed in the function's first @@ -26,8 +38,17 @@ function isLongerThan (val1, val2) { function hasOddNumberVowels (val1) { // TODO: write code in this function body to pass the tests + const vowels = ["a", "e", "i", "o", "u"] + let countVowels = 0 + for( let i = 0; i < val1.length; i++){ + if(vowels.includes(val1[i].toLowerCase())){ + countVowels++ + } + } + return Boolean(countVowels % 2) + + } -} // 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 +56,11 @@ function hasOddNumberVowels (val1) { function getMiddleLetter (val1) { // TODO: write code in this function body to pass the tests - + if (val1.length % 2 === 0) { + return val1[val1.length / 2 - 1] + val1[val1.length / 2]; + } else { + return val1[(val1.length + 1) / 2 - 1]; + } } // This function should return the name of the season for the provided @@ -50,6 +75,46 @@ function getMiddleLetter (val1) { function seasonForMonth (monthName) { // TODO: write code in this function body to pass the tests + let season = ""; + switch (monthName) { + case "March": + season = "Spring"; + break; + case "April": + season = "Spring"; + break; + case "May": + season = "Spring"; + break; + case "June": + season = "Summer"; + break; + case "July": + season = "Summer"; + break; + case "August": + season = "Summer"; + break; + case "September": + season = "Autumn"; + break; + case "October": + season = "Autumn"; + break; + case "November": + season = "Autumn"; + break; + case "December": + season = "Winter"; + break; + case "January": + season = "Winter"; + break; + case "February": + season = "Winter"; + break; + } + return season; } module.exports = { diff --git a/src/data-types/strings.js b/src/data-types/strings.js index cae85d68..26ef9a44 100644 --- a/src/data-types/strings.js +++ b/src/data-types/strings.js @@ -6,7 +6,7 @@ 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 = "Jane" + " " + "Smith" +const fullName = firstName + " " + secondName // Set this variable to the 10th character of the alphabet variable const tenthCharacterOfAlphabet = alphabet[9]