From 5ef801faed7a0cbe29e81fafac6dac00bef60613 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Thu, 3 Mar 2022 12:05:21 +0000 Subject: [PATCH 01/29] Variable assignment completed --- 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..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 fefb8f600cae5afdc7ce370de753208ab88ea46a Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Thu, 3 Mar 2022 12:37:27 +0000 Subject: [PATCH 02/29] Variable declaration completed --- src/variables/declaration.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/variables/declaration.js b/src/variables/declaration.js index 8afaa55b..aea3da37 100644 --- a/src/variables/declaration.js +++ b/src/variables/declaration.js @@ -1,5 +1,8 @@ // +let firstName = "Jane" +console.log(firstName) // +let age = 35 // // TODO: Declare the variables firstName and age so that the tests pass From 83e8a99018759e68015d79bc9371f7688b2b7636 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Thu, 3 Mar 2022 15:52:36 +0000 Subject: [PATCH 03/29] 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..323b4a6e 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 = 8 + 16 // Set this variable to numThree multiplied by numTwo -const numThreeTimesNumTwo = NaN +const numThreeTimesNumTwo = 32 * 16 // Set this variable to numThree divided by numOne -const numThreeDividedByNumOne = NaN +const numThreeDividedByNumOne = 32 / 8 // Set this variable to numThree minus numOne -const numThreeMinusNumOne = NaN +const numThreeMinusNumOne = 32 - 8 // Set this variable to the sum of numOne, numTwo and numThree -const sum = NaN +const sum = 8 + 16 + 32 // Set this variable to the sum of (numOne, numTwo, numThree) divided by numOne -const numBytes = NaN +const numBytes = (8 + 16 + 32) / 8 // do not edit the exported object. module.exports = { From 6f19744631055046f07a0da118d6e96aff6539cb Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Thu, 3 Mar 2022 16:21:34 +0000 Subject: [PATCH 04/29] 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..d9470d47 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 = 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 8214b484afa2285ca1c28841f428a14fe7ded3f2 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Thu, 3 Mar 2022 17:05:22 +0000 Subject: [PATCH 05/29] Arrays 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..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 14c9e0e3afb46f12d318d28a25fadf29f7824d9c Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Thu, 3 Mar 2022 17:56:48 +0000 Subject: [PATCH 06/29] Arrays adding and removing 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..81913d76 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 dec5ab74862d8d7dd1e8d62ce930624cabc6d39a Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Sun, 6 Mar 2022 22:33:24 +0000 Subject: [PATCH 07/29] Object Keys done --- src/data-types/objects/object-keys.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/data-types/objects/object-keys.js b/src/data-types/objects/object-keys.js index 4999e940..673a0301 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 = book.name // 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 = { From f1854410d372b37430e15bdac8c89c49c311b53e Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Sun, 6 Mar 2022 22:49:33 +0000 Subject: [PATCH 08/29] 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..d8ffa598 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 b9584600b0fe5cf6e145ef3dd926adcde7a0ce1d Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Sun, 6 Mar 2022 23:01:04 +0000 Subject: [PATCH 09/29] objects and arrays done --- src/data-types/objects/objects-and-arrays.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/data-types/objects/objects-and-arrays.js b/src/data-types/objects/objects-and-arrays.js index e4819467..e0a73f6a 100644 --- a/src/data-types/objects/objects-and-arrays.js +++ b/src/data-types/objects/objects-and-arrays.js @@ -22,10 +22,18 @@ 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 = 2 // Set this variable to the first element in of the baskets voucher codes array -const firstVoucherCode = null +const firstVoucherCode = 'AA-AA-A' + +basket.items[0].price = 2 + +basket.items[2] = ({ + name: 'Oranges', + price: 0.75, + quantity: 4 +}) // Do not edit this exported object module.exports = { From f57d789707ffc98b6ade70f6cf3457865f5329e1 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Mon, 7 Mar 2022 13:39:34 +0000 Subject: [PATCH 10/29] For Loop Basic done --- src/loops/for-loop-basic.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/loops/for-loop-basic.js b/src/loops/for-loop-basic.js index 38a5c971..14f5287f 100644 --- a/src/loops/for-loop-basic.js +++ b/src/loops/for-loop-basic.js @@ -4,12 +4,26 @@ 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 +const numbers = [0, 2, 4, 6]; +for (let i = 0; i < numbers.length; i++) { + if (numbers[i]) 2 === 0; + evenNums.push(numbers[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 1a0a6c7ca52d62fc40357d840ab31942b8110c17 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Mon, 7 Mar 2022 17:32:47 +0000 Subject: [PATCH 11/29] Loops and Arrays exercise --- src/loops/for-loop-and-arrays.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/loops/for-loop-and-arrays.js b/src/loops/for-loop-and-arrays.js index 682995ec..ae8c1e4e 100644 --- a/src/loops/for-loop-and-arrays.js +++ b/src/loops/for-loop-and-arrays.js @@ -6,19 +6,33 @@ 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= 0; i--) { + numsReversed.push(nums[i]); +} // do not change below this line module.exports = { From 2fb3708ff9126a877aba539a6bca9d346f080927 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Tue, 8 Mar 2022 11:43:52 +0000 Subject: [PATCH 12/29] calling functions done --- src/functions/calling-functions.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/functions/calling-functions.js b/src/functions/calling-functions.js index f44038d6..d4b0e8f9 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 = { From 2e21ff17f107169c537ed68fa036b02822280aa2 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Tue, 8 Mar 2022 17:47:17 +0000 Subject: [PATCH 13/29] creating function complete --- src/functions/creating-functions.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/functions/creating-functions.js b/src/functions/creating-functions.js index 2d2ac5e6..c0f81ba7 100644 --- a/src/functions/creating-functions.js +++ b/src/functions/creating-functions.js @@ -7,6 +7,9 @@ // 2 | 3 // // 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! @@ -18,9 +21,12 @@ // Aiyana | Hi, Aiyana :) // // TODO: write code below +function introducePerson(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: incrementNumber, // change undefined to be the name of the function you defined to increment a number (the first TODO) + b: introducePerson // change undefined to be the name of the function you defined to say hi (the second TODO) } From ec0d8443365cc9c789f079917589d62a4f8a6542 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Tue, 8 Mar 2022 23:49:50 +0000 Subject: [PATCH 14/29] creating functions multiple args complete --- .../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..21058bab 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 +function 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 @@ -21,9 +28,16 @@ // error, 10 | ERROR!!!!!!!!!! // // TODO: write code below +function upperCase (word, number) { + const exclamationMark = [] + for (let i = 0; i < number; 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) - b: undefined // change undefined to be the name of the function defined to return the string with exclamations (the second todo) + a: createArray, // change undefined to be the name of the function defined to create the range of numbers (the first todo) + b: upperCase // change undefined to be the name of the function defined to return the string with exclamations (the second todo) } From 1a23e2144090b6c40da0686f13acfec05afe226b Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Wed, 9 Mar 2022 12:54:06 +0000 Subject: [PATCH 15/29] creating functions multiple args completed (Ed example) --- .../creating-functions-multiple-args.js | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/functions/creating-functions-multiple-args.js b/src/functions/creating-functions-multiple-args.js index 21058bab..f1e0bdfb 100644 --- a/src/functions/creating-functions-multiple-args.js +++ b/src/functions/creating-functions-multiple-args.js @@ -28,16 +28,23 @@ function createArray (lower, upper) { // error, 10 | ERROR!!!!!!!!!! // // TODO: write code below -function upperCase (word, number) { - const exclamationMark = [] - for (let i = 0; i < number; i++) { - exclamationMark.push('!') - } - return word.toUpperCase() + exclamationMark.join('') +function stringWithUpperCase (string, num) { + +let outcome = string.toUpperCase() +let exclamationMarks = '' + +for (let i = 0; i Date: Wed, 9 Mar 2022 13:06:13 +0000 Subject: [PATCH 16/29] boolean conditions completed --- src/conditional-flow/boolean-conditions.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/conditional-flow/boolean-conditions.js b/src/conditional-flow/boolean-conditions.js index 70b623d4..9033d0dd 100644 --- a/src/conditional-flow/boolean-conditions.js +++ b/src/conditional-flow/boolean-conditions.js @@ -4,7 +4,8 @@ function getResult (didPass) { // TODO: write code in this function body to pass the tests - +if (true) alert('Well done, you passed!') +if (false) alert('Sorry, try again') } module.exports = { From b761c62b677a8eec699d540c09f80088902d4f19 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Wed, 9 Mar 2022 15:17:02 +0000 Subject: [PATCH 17/29] String Conditions NOT completed --- src/conditional-flow/numeric-conditions.js | 20 ++++++++++++++++++++ src/conditional-flow/string-conditions.js | 18 +++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/conditional-flow/numeric-conditions.js b/src/conditional-flow/numeric-conditions.js index 0f6656a5..ba178588 100644 --- a/src/conditional-flow/numeric-conditions.js +++ b/src/conditional-flow/numeric-conditions.js @@ -4,6 +4,12 @@ function isArrayEmpty (array) { // TODO: write code in this function body to pass the tests + if (array === []) { + return true + } + else { + return false + } } @@ -11,6 +17,12 @@ function isArrayEmpty (array) { function isGreaterThan (num1, num2) { // TODO: write code in this function body to pass the tests +if (num1 > num2) { + return true +} +else { + return false + } } @@ -19,6 +31,12 @@ function findLowest (nums) { // TODO: write code in this function body to pass the tests + // PseudoCode: + // 1. You want to find the lowest number inside this array [10, 8, 4, 1, 8]. + // 2. It's 1, so show it using Math.min + // 3. return the result. It will happen automatically when you write down the const name (lowestNum) + const lowestNum = Math.min(...nums) + return lowestNum } module.exports = { @@ -26,3 +44,5 @@ module.exports = { b: isGreaterThan, c: findLowest } + +// npx jasmine spec/conditional-flow/numeric-conditions.spec.js \ No newline at end of file diff --git a/src/conditional-flow/string-conditions.js b/src/conditional-flow/string-conditions.js index d91bfaf0..95b6aaf6 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 From 9a3f50a8c167530c4b21125d3ef09e7ea3705aed Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Thu, 10 Mar 2022 21:20:57 +0000 Subject: [PATCH 18/29] string conditions completed --- src/conditional-flow/string-conditions.js | 29 +++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/conditional-flow/string-conditions.js b/src/conditional-flow/string-conditions.js index 95b6aaf6..f406f5ad 100644 --- a/src/conditional-flow/string-conditions.js +++ b/src/conditional-flow/string-conditions.js @@ -38,16 +38,28 @@ if (val1.length > val2.length) { 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 // of characters. If there are an even number of characters the function should return // the middle two letters 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 @@ -62,6 +74,17 @@ function getMiddleLetter (val1) { function seasonForMonth (monthName) { // TODO: write code in this function body to pass the tests + if (monthName === 'March' || monthName === 'April' || monthName === 'May') { + return 'Spring' + } else if (monthName === 'June' || monthName === 'July' || monthName === 'August') { + return 'Summer' + } else if (monthName === 'September' || monthName === 'October' || monthName === 'November') { + return 'Autumn' + } else if (monthName === 'December' || monthName === 'January' || monthName === 'February') { + return 'Winter' + } else { + return '' + } } module.exports = { @@ -72,3 +95,5 @@ module.exports = { e: getMiddleLetter, f: seasonForMonth } + +// npx jasmine spec/conditional-flow/string-conditions.spec.js \ No newline at end of file From 901194b83161177042ee3f89d63c15d535bcdb95 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Sun, 13 Mar 2022 12:02:37 +0000 Subject: [PATCH 19/29] Multiple Conditions completed --- 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..8cd59e6a 100644 --- a/src/conditional-flow/multiple-conditions.js +++ b/src/conditional-flow/multiple-conditions.js @@ -4,16 +4,25 @@ function isInRange (num, lower, upper) { // TODO: write code in this function body to pass the tests - +if (num >= lower && num <= upper) { + return true; +} else { + return false; +} } + // 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; +} else { + return false; +} } // This function should return a string that describes the provided age value. The @@ -31,10 +40,21 @@ 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 >= 1 && age <= 4) { + return "Toddler"; + } else if (age >= 5 && age <= 12) { + return "Child" + } else if (age >= 13 && age <= 19) { + return "Teenager" + } else if (age >= 20) { + return "Adult" + } } module.exports = { a: isInRange, b: isHelloOrGoodbye, c: getAgeDescription -} +} \ No newline at end of file From 9f9ac073ed29d7a2bba82034780dca916c2ede3d Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Sun, 13 Mar 2022 12:12:00 +0000 Subject: [PATCH 20/29] Boolean conditions refactored --- src/conditional-flow/boolean-conditions.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/conditional-flow/boolean-conditions.js b/src/conditional-flow/boolean-conditions.js index 9033d0dd..36953d36 100644 --- a/src/conditional-flow/boolean-conditions.js +++ b/src/conditional-flow/boolean-conditions.js @@ -4,10 +4,14 @@ function getResult (didPass) { // TODO: write code in this function body to pass the tests -if (true) alert('Well done, you passed!') -if (false) alert('Sorry, try again') +if (didPass === true) +return 'Well done, you passed!' +else (didPass === false) +return 'Sorry, try again' } module.exports = { a: getResult } + +// npx jasmine spec/conditional-flow/boolean-conditions.spec.js \ No newline at end of file From 1e95c7830d16c89f68fa4eeb7c51c3808a94a95c Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Sun, 13 Mar 2022 12:14:11 +0000 Subject: [PATCH 21/29] Numeric Conditions refactored --- src/conditional-flow/numeric-conditions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conditional-flow/numeric-conditions.js b/src/conditional-flow/numeric-conditions.js index ba178588..0bf4472c 100644 --- a/src/conditional-flow/numeric-conditions.js +++ b/src/conditional-flow/numeric-conditions.js @@ -4,7 +4,7 @@ function isArrayEmpty (array) { // TODO: write code in this function body to pass the tests - if (array === []) { + if (array.length === 0) { return true } else { From 32ba2325c54fc11aa0f88acaf27062de37b892eb Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Sun, 13 Mar 2022 12:20:49 +0000 Subject: [PATCH 22/29] Arrays - accessing elements refactored --- src/data-types/arrays/accessing-elements.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/data-types/arrays/accessing-elements.js b/src/data-types/arrays/accessing-elements.js index 4dbc3403..b54d93b4 100644 --- a/src/data-types/arrays/accessing-elements.js +++ b/src/data-types/arrays/accessing-elements.js @@ -7,10 +7,10 @@ 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 = cities.length @@ -22,3 +22,5 @@ module.exports = { c: firstCity, d: lengthOfCitiesArray } + +// npx jasmine spec/data-types/arrays/accessing-elements.spec.js \ No newline at end of file From 13d335bcaafc5237fc701d04346e5414f6c72f73 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Sun, 13 Mar 2022 12:24:22 +0000 Subject: [PATCH 23/29] Arrays adding-removing elements refactored --- src/data-types/arrays/adding-removing-elements.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/data-types/arrays/adding-removing-elements.js b/src/data-types/arrays/adding-removing-elements.js index 81913d76..330731e5 100644 --- a/src/data-types/arrays/adding-removing-elements.js +++ b/src/data-types/arrays/adding-removing-elements.js @@ -19,10 +19,10 @@ numbers.push(4) cities.unshift('Rio') // Use an array method to remove the first item from colours -colours.shift('Red') +colours.shift() // 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) @@ -41,3 +41,5 @@ module.exports = { g: fruits, h: pear } + +// npx jasmine spec/data-types/arrays/adding-removing-elements.spec.js \ No newline at end of file From 942848b55b6d0069e9ba631a56eafab5fbb63584 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Sun, 13 Mar 2022 12:27:20 +0000 Subject: [PATCH 24/29] data tyoes numbers refactored --- src/data-types/numbers.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/data-types/numbers.js b/src/data-types/numbers.js index 323b4a6e..fe0ad87d 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 = 8 + 16 +const numOnePlusNumTwo = numOne + numTwo // Set this variable to numThree multiplied by numTwo -const numThreeTimesNumTwo = 32 * 16 +const numThreeTimesNumTwo = numThree * numTwo // Set this variable to numThree divided by numOne -const numThreeDividedByNumOne = 32 / 8 +const numThreeDividedByNumOne = numThree / numOne // Set this variable to numThree minus numOne -const numThreeMinusNumOne = 32 - 8 +const numThreeMinusNumOne = numThree - numOne // Set this variable to the sum of numOne, numTwo and numThree -const sum = 8 + 16 + 32 +const sum = numOne + numTwo + numThree // Set this variable to the sum of (numOne, numTwo, numThree) divided by numOne -const numBytes = (8 + 16 + 32) / 8 +const numBytes = (numOne + numTwo + numThree) / numOne // do not edit the exported object. module.exports = { @@ -32,3 +32,5 @@ module.exports = { e: sum, f: numBytes } + +// npx jasmine spec/data-types/numbers.spec.js \ No newline at end of file From ca20171f2073b447f2a3347e29f105c4f40ae919 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Sun, 13 Mar 2022 12:30:51 +0000 Subject: [PATCH 25/29] data types - creating objects refactored --- src/data-types/objects/creating-objects.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/data-types/objects/creating-objects.js b/src/data-types/objects/creating-objects.js index d8ffa598..d6d05935 100644 --- a/src/data-types/objects/creating-objects.js +++ b/src/data-types/objects/creating-objects.js @@ -6,10 +6,9 @@ const person = { } const computer = { form: 'laptop', - specs: ( + specs: {memory: '16GB', storage: '1TB'} - ) } // Do not edit this exported object @@ -17,3 +16,5 @@ module.exports = { person: person, computer: computer } + +// npx jasmine spec/data-types/objects/creating-objects.spec.js \ No newline at end of file From c73e6a802112d2584820503493295ccd50317216 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Sun, 13 Mar 2022 12:38:55 +0000 Subject: [PATCH 26/29] for loop basic refactored --- src/loops/for-loop-basic.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/loops/for-loop-basic.js b/src/loops/for-loop-basic.js index 14f5287f..93f309df 100644 --- a/src/loops/for-loop-basic.js +++ b/src/loops/for-loop-basic.js @@ -16,7 +16,7 @@ for (let i = 5; i < 11; i++) { // TODO: Write a for loop that adds all the even numbers between 0 and 6 (0, 2, 4, 6) to evenNums const numbers = [0, 2, 4, 6]; for (let i = 0; i < numbers.length; i++) { - if (numbers[i]) 2 === 0; + if (numbers[i] % 2 === 0); evenNums.push(numbers[i]); } @@ -32,3 +32,5 @@ module.exports = { c: evenNums, d: countdown } + +// npx jasmine spec/loops/for-loop-basic.spec.js \ No newline at end of file From 57ce1ee616304d169f5288ece021d9d9146112db Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Sun, 13 Mar 2022 12:50:38 +0000 Subject: [PATCH 27/29] object and arrays refactored --- src/data-types/objects/objects-and-arrays.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/data-types/objects/objects-and-arrays.js b/src/data-types/objects/objects-and-arrays.js index e0a73f6a..8e381271 100644 --- a/src/data-types/objects/objects-and-arrays.js +++ b/src/data-types/objects/objects-and-arrays.js @@ -29,11 +29,13 @@ const firstVoucherCode = 'AA-AA-A' basket.items[0].price = 2 -basket.items[2] = ({ +const orange = { name: 'Oranges', price: 0.75, quantity: 4 -}) +}; + +basket.items.push (orange); // Do not edit this exported object module.exports = { From ba950b8813a11f0195a18f80de6e5e08ed585458 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Sun, 13 Mar 2022 12:51:51 +0000 Subject: [PATCH 28/29] objects and arrays refactored --- src/data-types/objects/objects-and-arrays.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data-types/objects/objects-and-arrays.js b/src/data-types/objects/objects-and-arrays.js index 8e381271..cfe5082b 100644 --- a/src/data-types/objects/objects-and-arrays.js +++ b/src/data-types/objects/objects-and-arrays.js @@ -35,7 +35,7 @@ const orange = { quantity: 4 }; -basket.items.push (orange); +basket.items.push (orange) // Do not edit this exported object module.exports = { From 4a69e1e58b37744fa63c7b58851abcc82269aed3 Mon Sep 17 00:00:00 2001 From: Anica Rahman Date: Sun, 13 Mar 2022 12:57:28 +0000 Subject: [PATCH 29/29] Demo completed --- src/demo/demo.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/demo/demo.js b/src/demo/demo.js index 9201bd8a..551a4e32 100644 --- a/src/demo/demo.js +++ b/src/demo/demo.js @@ -4,14 +4,16 @@ 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 = { a: numThree, b: numOnePlusNumTwo } + +// npx jasmine spec/demo/demo.spec.js \ No newline at end of file