From b1a03f2a1eae4f99f1ac183e602628fec353b2f2 Mon Sep 17 00:00:00 2001 From: George T Date: Mon, 13 Dec 2021 13:03:46 +0000 Subject: [PATCH 01/25] Completed demo exercise --- package-lock.json | 1 + src/demo/demo.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/demo/demo.js b/src/demo/demo.js index 9201bd8a..ee9026fe 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 = 12 // Set this variable to numOne plus numTwo // do not edit this section module.exports = { From f9eba982cd016074c9d8724de8f11e2dcf2916e8 Mon Sep 17 00:00:00 2001 From: George T Date: Mon, 13 Dec 2021 13:18:58 +0000 Subject: [PATCH 02/25] Variables complete --- src/variables/assignment.js | 4 ++-- src/variables/declaration.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) 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 = { diff --git a/src/variables/declaration.js b/src/variables/declaration.js index 8afaa55b..22db3b16 100644 --- a/src/variables/declaration.js +++ b/src/variables/declaration.js @@ -2,7 +2,8 @@ // // // 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 5e4a2d03f00c648ea4ba64801b9ffb954e5112db Mon Sep 17 00:00:00 2001 From: George T Date: Mon, 13 Dec 2021 17:02:28 +0000 Subject: [PATCH 03/25] Loops completed --- src/loops/for-loop-and-arrays.js | 15 +++++++++++++++ src/loops/for-loop-basic.js | 16 ++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/loops/for-loop-and-arrays.js b/src/loops/for-loop-and-arrays.js index 682995ec..f8c3576d 100644 --- a/src/loops/for-loop-and-arrays.js +++ b/src/loops/for-loop-and-arrays.js @@ -7,18 +7,33 @@ 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 Date: Mon, 13 Dec 2021 17:22:08 +0000 Subject: [PATCH 04/25] Data types complete --- src/conditional-flow/boolean-conditions.js | 9 ++++++ src/data-types/arrays/accessing-elements.js | 8 +++--- .../arrays/adding-removing-elements.js | 14 +++++----- src/data-types/numbers.js | 12 ++++---- src/data-types/objects/creating-objects.js | 14 ++++++++-- src/data-types/objects/object-keys.js | 14 ++++++++-- src/data-types/objects/objects-and-arrays.js | 28 +++++++++++-------- src/data-types/strings.js | 8 +++--- src/loops/for-loop-and-arrays.js | 6 ++-- src/variables/assignment.js | 4 +-- 10 files changed, 75 insertions(+), 42 deletions(-) diff --git a/src/conditional-flow/boolean-conditions.js b/src/conditional-flow/boolean-conditions.js index 70b623d4..5f366761 100644 --- a/src/conditional-flow/boolean-conditions.js +++ b/src/conditional-flow/boolean-conditions.js @@ -4,6 +4,15 @@ function getResult (didPass) { // TODO: write code in this function body to pass the tests + var didPass = new Boolean(true); + +// if (didPass = true) { +// console.log('Well done, you passed!'); +// } + +// else { +// console.log('Sorry, try again'); +// } } diff --git a/src/data-types/arrays/accessing-elements.js b/src/data-types/arrays/accessing-elements.js index 374a19bb..d492b80d 100644 --- a/src/data-types/arrays/accessing-elements.js +++ b/src/data-types/arrays/accessing-elements.js @@ -4,16 +4,16 @@ const cities = ['London', 'Shanghai', 'New York', 'Delhi', 'Kuala Lumpur'] // TODO: write code to pass the tests // Set names equal to an array containing 'Bob', 'Jane', 'Joanna' in that order -const names = null +const names = ['Bob', 'Jane', 'Joanna']; // Set fourthCity to the 4th element in the cities array -const fourthCity = '' +const fourthCity = cities[3]; // Set firstCity to the 1st element in the cities array -const firstCity = '' +const firstCity = cities[0]; // Set lengthOfCitiesArray to the length of the cities array -const lengthOfCitiesArray = NaN +const lengthOfCitiesArray = cities.length; // Do not edit this exported object module.exports = { diff --git a/src/data-types/arrays/adding-removing-elements.js b/src/data-types/arrays/adding-removing-elements.js index 69e559e8..a22efa8a 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 = { diff --git a/src/data-types/numbers.js b/src/data-types/numbers.js index 01dd70de..c4852b03 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 = { diff --git a/src/data-types/objects/creating-objects.js b/src/data-types/objects/creating-objects.js index 1939e6b0..591b9eb2 100644 --- a/src/data-types/objects/creating-objects.js +++ b/src/data-types/objects/creating-objects.js @@ -1,7 +1,17 @@ // 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 = { diff --git a/src/data-types/objects/object-keys.js b/src/data-types/objects/object-keys.js index 4999e940..968909dd 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 = book.isbn.isbn10; + +book.category = 'Programming'; + +book.pages = 464; + +book.isbn.isbn13 = isbn13; + +delete book.dimensions; + +delete book.isbn.asin; // Do not edit this exported object module.exports = { diff --git a/src/data-types/objects/objects-and-arrays.js b/src/data-types/objects/objects-and-arrays.js index e4819467..90a10100 100644 --- a/src/data-types/objects/objects-and-arrays.js +++ b/src/data-types/objects/objects-and-arrays.js @@ -4,32 +4,36 @@ const basket = { { name: 'Apple', quantity: 10, - price: 1 + price: 1, }, { name: 'Lemon', quantity: 2, - price: 0.5 - } + price: 0.5, + }, ], - voucherCodes: [ - 'AA-AA-A', - 'BB-BB-B' - ] -} + voucherCodes: ['AA-AA-A', 'BB-BB-B'], +}; // TODO: write code in this section to pass the tests. You will need to add new code // as well as modify some of the existing code // Set this variable to the length of the baskets voucher codes array -const numberOfVoucherCodes = 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', + quantity: 4, + price: 0.75, +}); // Do not edit this exported object module.exports = { basket: basket, numberOfVoucherCodes: numberOfVoucherCodes, - firstVoucherCode: firstVoucherCode -} + firstVoucherCode: firstVoucherCode, +}; diff --git a/src/data-types/strings.js b/src/data-types/strings.js index a8eb8c5b..db3dea75 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 = { diff --git a/src/loops/for-loop-and-arrays.js b/src/loops/for-loop-and-arrays.js index f8c3576d..4126bf37 100644 --- a/src/loops/for-loop-and-arrays.js +++ b/src/loops/for-loop-and-arrays.js @@ -7,19 +7,19 @@ 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 Date: Tue, 14 Dec 2021 16:21:17 +0000 Subject: [PATCH 05/25] All exercises completed --- src/conditional-flow/boolean-conditions.js | 16 ++-- src/conditional-flow/multiple-conditions.js | 14 ++- src/conditional-flow/numeric-conditions.js | 19 +++- src/conditional-flow/string-conditions.js | 91 +++++++++++++++---- src/functions/calling-functions.js | 6 +- .../creating-functions-multiple-args.js | 21 ++++- src/functions/creating-functions.js | 10 +- src/variables/declaration.js | 1 + 8 files changed, 135 insertions(+), 43 deletions(-) diff --git a/src/conditional-flow/boolean-conditions.js b/src/conditional-flow/boolean-conditions.js index 5f366761..c990f765 100644 --- a/src/conditional-flow/boolean-conditions.js +++ b/src/conditional-flow/boolean-conditions.js @@ -4,16 +4,12 @@ function getResult (didPass) { // TODO: write code in this function body to pass the tests - var didPass = new Boolean(true); - -// if (didPass = true) { -// console.log('Well done, you passed!'); -// } - -// else { -// console.log('Sorry, try again'); -// } - + if (didPass === true) { + 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..f65443d1 100644 --- a/src/conditional-flow/multiple-conditions.js +++ b/src/conditional-flow/multiple-conditions.js @@ -2,18 +2,16 @@ // 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 ? true : 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 - + return val1 == 'Hello' || val1 == 'Goodbye' ? true : false; } // This function should return a string that describes the provided age value. The @@ -28,9 +26,15 @@ function isHelloOrGoodbye (val1) { // 5-12 | Child // 13-19 | Teenager // 20+ | Adult -function getAgeDescription (age) { +function getAgeDescription (age) { + // TODO: write code in this function body to pass the tests + return age === 0 ? 'Baby' : + age >= 1 && age <= 4 ? 'Toddler' : + age >= 5 && age <= 12 ? 'Child' : + age >= 13 && age <= 19 ? 'Teenager' : + age >= 20 ? 'Adult' : false; } module.exports = { diff --git a/src/conditional-flow/numeric-conditions.js b/src/conditional-flow/numeric-conditions.js index 0f6656a5..c5cd5a8d 100644 --- a/src/conditional-flow/numeric-conditions.js +++ b/src/conditional-flow/numeric-conditions.js @@ -4,21 +4,34 @@ function isArrayEmpty (array) { // TODO: write code in this function body to pass the tests - + return array.length == 0 ? true : false; } // This function should return true if num1 is greater than num2, false otherwise function isGreaterThan (num1, num2) { // TODO: write code in this function body to pass the tests - + 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 - + let i = 0; + let lowest = nums[i]; + + for (i = 0; i < nums.length; i++) { + if (lowest > nums[i]) { + lowest = nums[i]; + } + } + return lowest; } module.exports = { diff --git a/src/conditional-flow/string-conditions.js b/src/conditional-flow/string-conditions.js index d91bfaf0..c324039b 100644 --- a/src/conditional-flow/string-conditions.js +++ b/src/conditional-flow/string-conditions.js @@ -1,41 +1,78 @@ // This function should return true if the passed string is equal to "Hello" -function isHello (val1) { - +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) { - +function isNotHello(val1) { + if (val1 !== 'Hello') { + return true; + } + else { + 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) { - +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 - } // This function should return true if the string passed in the function's first // argument has an odd number of vowels -function hasOddNumberVowels (val1) { +function hasOddNumberVowels(val1) { + let count = 0; + let valLower = val1.toLowerCase(); + + for (i = 0; i < valLower.length; i++) { + if ( + valLower[i] == 'a' || valLower[i] == 'i' || + valLower[i] == 'e' || valLower[i] == 'o' || + valLower[i] == 'u' + ) { + count++; + } + } + + if (count % 2 === 1) { + return true; + } + else { + return false; + } // TODO: write code in this function body to pass the tests - } // 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) { +function getMiddleLetter(val1) { // TODO: write code in this function body to pass the tests - + if (val1.length % 2 === 1) { + let oddChar = Math.floor(val1.length / 2); + return val1[oddChar]; + } + else { + let evenChar = val1.length / 2; + return val1[evenChar - 1] + val1[evenChar]; + } } // This function should return the name of the season for the provided @@ -47,9 +84,31 @@ function getMiddleLetter (val1) { // Summer - June to August // Autumn - September to November // Winter - December to February -function seasonForMonth (monthName) { +function seasonForMonth(monthName) { // TODO: write code in this function body to pass the tests + // let inputMonth; + + switch (monthName) { + case 'March': + case 'April': + case 'May': + return 'Spring'; + case 'June': + case 'July': + case 'August': + return 'Summer'; + case 'September': + case 'October': + case 'November': + return 'Autumn'; + case 'December': + case 'January': + case 'February': + return 'Winter'; + default: + return ''; + } } module.exports = { @@ -58,5 +117,5 @@ module.exports = { c: isLongerThan, d: hasOddNumberVowels, e: getMiddleLetter, - f: seasonForMonth -} + f: seasonForMonth, +}; \ No newline at end of file diff --git a/src/functions/calling-functions.js b/src/functions/calling-functions.js index f44038d6..36a6a69b 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 = { diff --git a/src/functions/creating-functions-multiple-args.js b/src/functions/creating-functions-multiple-args.js index a437ae8a..b943690f 100644 --- a/src/functions/creating-functions-multiple-args.js +++ b/src/functions/creating-functions-multiple-args.js @@ -9,7 +9,13 @@ // -1, 1 | [-1, 0, 1] // // TODO: write code below - +function between(firstNum, lastNum) { + let array = []; + for (i = firstNum; i <= lastNum; 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 @@ -21,9 +27,16 @@ // error, 10 | ERROR!!!!!!!!!! // // TODO: write code below - +function addExclamation(word, number) { + let exclamations = ''; + + for (i = 0; i < number; i++) { + exclamations += '!'; + } + return word.toUpperCase() + exclamations; +} // 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: between, // change undefined to be the name of the function defined to create the range of numbers (the first todo) + b: addExclamation // change undefined to be the name of the function defined to return the string with exclamations (the second todo) } diff --git a/src/functions/creating-functions.js b/src/functions/creating-functions.js index 2d2ac5e6..11857778 100644 --- a/src/functions/creating-functions.js +++ b/src/functions/creating-functions.js @@ -7,6 +7,9 @@ // 2 | 3 // // TODO: write code below +function addOne(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 greeting(name) { + return 'Hi, ' + name.replace(name[0], name[0].toUpperCase()) + ' :)'; +} // 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: addOne, // change undefined to be the name of the function you defined to increment a number (the first TODO) + b: greeting // change undefined to be the name of the function you defined to say hi (the second TODO) } diff --git a/src/variables/declaration.js b/src/variables/declaration.js index 22db3b16..9b6c6f3c 100644 --- a/src/variables/declaration.js +++ b/src/variables/declaration.js @@ -4,6 +4,7 @@ // 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 b174a519e43a4ce5472e2e8f4533f526850ccdcf Mon Sep 17 00:00:00 2001 From: George T Date: Wed, 5 Jan 2022 16:08:46 +0000 Subject: [PATCH 06/25] restart exercises --- src/conditional-flow/boolean-conditions.js | 7 +- src/conditional-flow/multiple-conditions.js | 14 +-- src/conditional-flow/numeric-conditions.js | 19 +--- src/conditional-flow/string-conditions.js | 91 ++++--------------- src/data-types/arrays/accessing-elements.js | 8 +- .../arrays/adding-removing-elements.js | 14 +-- src/data-types/numbers.js | 12 +-- src/data-types/objects/creating-objects.js | 14 +-- src/data-types/objects/object-keys.js | 14 +-- src/data-types/objects/objects-and-arrays.js | 28 +++--- src/data-types/strings.js | 8 +- src/demo/demo.js | 4 +- src/functions/calling-functions.js | 6 +- .../creating-functions-multiple-args.js | 21 +---- src/functions/creating-functions.js | 10 +- src/loops/for-loop-and-arrays.js | 15 --- src/loops/for-loop-basic.js | 16 +--- src/variables/assignment.js | 4 +- src/variables/declaration.js | 2 - 19 files changed, 79 insertions(+), 228 deletions(-) diff --git a/src/conditional-flow/boolean-conditions.js b/src/conditional-flow/boolean-conditions.js index c990f765..70b623d4 100644 --- a/src/conditional-flow/boolean-conditions.js +++ b/src/conditional-flow/boolean-conditions.js @@ -4,12 +4,7 @@ function getResult (didPass) { // TODO: write code in this function body to pass the tests - if (didPass === true) { - 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 f65443d1..80420abf 100644 --- a/src/conditional-flow/multiple-conditions.js +++ b/src/conditional-flow/multiple-conditions.js @@ -2,16 +2,18 @@ // 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 ? true : 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 - return val1 == 'Hello' || val1 == 'Goodbye' ? true : false; + } // This function should return a string that describes the provided age value. The @@ -26,15 +28,9 @@ function isHelloOrGoodbye (val1) { // 5-12 | Child // 13-19 | Teenager // 20+ | Adult - function getAgeDescription (age) { - + // TODO: write code in this function body to pass the tests - return age === 0 ? 'Baby' : - age >= 1 && age <= 4 ? 'Toddler' : - age >= 5 && age <= 12 ? 'Child' : - age >= 13 && age <= 19 ? 'Teenager' : - age >= 20 ? 'Adult' : false; } module.exports = { diff --git a/src/conditional-flow/numeric-conditions.js b/src/conditional-flow/numeric-conditions.js index c5cd5a8d..0f6656a5 100644 --- a/src/conditional-flow/numeric-conditions.js +++ b/src/conditional-flow/numeric-conditions.js @@ -4,34 +4,21 @@ function isArrayEmpty (array) { // TODO: write code in this function body to pass the tests - return array.length == 0 ? true : false; + } // This function should return true if num1 is greater than num2, false otherwise function isGreaterThan (num1, num2) { // TODO: write code in this function body to pass the tests - 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 - let i = 0; - let lowest = nums[i]; - - for (i = 0; i < nums.length; i++) { - if (lowest > nums[i]) { - lowest = nums[i]; - } - } - return lowest; + } module.exports = { diff --git a/src/conditional-flow/string-conditions.js b/src/conditional-flow/string-conditions.js index c324039b..d91bfaf0 100644 --- a/src/conditional-flow/string-conditions.js +++ b/src/conditional-flow/string-conditions.js @@ -1,78 +1,41 @@ // This function should return true if the passed string is equal to "Hello" -function isHello(val1) { +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) { - if (val1 !== 'Hello') { - return true; - } - else { - return false; - } +function isNotHello (val1) { + // 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; - } +function isLongerThan (val1, val2) { + // TODO: write code in this function body to pass the tests + } // This function should return true if the string passed in the function's first // argument has an odd number of vowels -function hasOddNumberVowels(val1) { - let count = 0; - let valLower = val1.toLowerCase(); - - for (i = 0; i < valLower.length; i++) { - if ( - valLower[i] == 'a' || valLower[i] == 'i' || - valLower[i] == 'e' || valLower[i] == 'o' || - valLower[i] == 'u' - ) { - count++; - } - } - - if (count % 2 === 1) { - return true; - } - else { - return false; - } +function hasOddNumberVowels (val1) { // TODO: write code in this function body to pass the tests + } // 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) { +function getMiddleLetter (val1) { // TODO: write code in this function body to pass the tests - if (val1.length % 2 === 1) { - let oddChar = Math.floor(val1.length / 2); - return val1[oddChar]; - } - else { - let evenChar = val1.length / 2; - return val1[evenChar - 1] + val1[evenChar]; - } + } // This function should return the name of the season for the provided @@ -84,31 +47,9 @@ function getMiddleLetter(val1) { // Summer - June to August // Autumn - September to November // Winter - December to February +function seasonForMonth (monthName) { -function seasonForMonth(monthName) { // TODO: write code in this function body to pass the tests - // let inputMonth; - - switch (monthName) { - case 'March': - case 'April': - case 'May': - return 'Spring'; - case 'June': - case 'July': - case 'August': - return 'Summer'; - case 'September': - case 'October': - case 'November': - return 'Autumn'; - case 'December': - case 'January': - case 'February': - return 'Winter'; - default: - return ''; - } } module.exports = { @@ -117,5 +58,5 @@ module.exports = { c: isLongerThan, d: hasOddNumberVowels, e: getMiddleLetter, - f: seasonForMonth, -}; \ No newline at end of file + f: seasonForMonth +} diff --git a/src/data-types/arrays/accessing-elements.js b/src/data-types/arrays/accessing-elements.js index d492b80d..374a19bb 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 = ['Bob', 'Jane', 'Joanna']; +const names = null // Set fourthCity to the 4th element in the cities array -const fourthCity = cities[3]; +const fourthCity = '' // Set firstCity to the 1st element in the cities array -const firstCity = cities[0]; +const firstCity = '' // Set lengthOfCitiesArray to the length of the cities array -const lengthOfCitiesArray = cities.length; +const lengthOfCitiesArray = NaN // Do not edit this exported object module.exports = { diff --git a/src/data-types/arrays/adding-removing-elements.js b/src/data-types/arrays/adding-removing-elements.js index a22efa8a..69e559e8 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('Fred'); +names.push(undefined) // Edit this code to add 4 to the end of the numbers array -numbers.push(4); +numbers.push(NaN) // Edit this code to add 'Rio' to the start of the cities array -cities.unshift('Rio'); +cities.unshift(undefined) // Use an array method to remove the first item from colours -colours.shift(); +colours // Use an array method to remove the last item from keys -keys.pop(); +keys // Use an array method to remove 'Jordon' from the countries array -countries.splice(1, 1); +countries.splice(NaN, NaN) // 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(); +const pear = fruits.undefined // Do not edit this exported object module.exports = { diff --git a/src/data-types/numbers.js b/src/data-types/numbers.js index c4852b03..01dd70de 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 = numOne + numTwo; +const numOnePlusNumTwo = NaN // Set this variable to numThree multiplied by numTwo -const numThreeTimesNumTwo = numThree * numTwo; +const numThreeTimesNumTwo = NaN // Set this variable to numThree divided by numOne -const numThreeDividedByNumOne = numThree / numOne; +const numThreeDividedByNumOne = NaN // Set this variable to numThree minus numOne -const numThreeMinusNumOne = numThree - numOne; +const numThreeMinusNumOne = NaN // Set this variable to the sum of numOne, numTwo and numThree -const sum = numOne + numTwo + numThree; +const sum = NaN // Set this variable to the sum of (numOne, numTwo, numThree) divided by numOne -const numBytes = (numOne + numTwo + numThree) / numOne; +const numBytes = NaN // do not edit the exported object. module.exports = { diff --git a/src/data-types/objects/creating-objects.js b/src/data-types/objects/creating-objects.js index 591b9eb2..1939e6b0 100644 --- a/src/data-types/objects/creating-objects.js +++ b/src/data-types/objects/creating-objects.js @@ -1,17 +1,7 @@ // 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 = { - name: 'Jane', - age: 32 -} - -const computer = { - form: 'laptop', - specs: { - memory: '16GB', - storage: '1TB' - } -} +const person = null +const computer = null // 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 968909dd..4999e940 100644 --- a/src/data-types/objects/object-keys.js +++ b/src/data-types/objects/object-keys.js @@ -17,20 +17,10 @@ const isbn13 = '978-0132350884' // as well as modify some of the existing code // Set this to the book name -const name = book.name; +const name = '' // Set this to the isbn 10 value -const isbn10 = book.isbn.isbn10; - -book.category = 'Programming'; - -book.pages = 464; - -book.isbn.isbn13 = isbn13; - -delete book.dimensions; - -delete book.isbn.asin; +const isbn10 = '' // Do not edit this exported object module.exports = { diff --git a/src/data-types/objects/objects-and-arrays.js b/src/data-types/objects/objects-and-arrays.js index 90a10100..e4819467 100644 --- a/src/data-types/objects/objects-and-arrays.js +++ b/src/data-types/objects/objects-and-arrays.js @@ -4,36 +4,32 @@ const basket = { { name: 'Apple', quantity: 10, - price: 1, + price: 1 }, { name: 'Lemon', quantity: 2, - price: 0.5, - }, + price: 0.5 + } ], - voucherCodes: ['AA-AA-A', 'BB-BB-B'], -}; + voucherCodes: [ + 'AA-AA-A', + 'BB-BB-B' + ] +} // TODO: write code in this section to pass the tests. You will need to add new code // as well as modify some of the existing code // Set this variable to the length of the baskets voucher codes array -const numberOfVoucherCodes = basket.voucherCodes.length; +const numberOfVoucherCodes = null // Set this variable to the first element in of the baskets voucher codes array -const firstVoucherCode = basket.voucherCodes[0]; -basket.items[0].price = 2; - -basket.items.push({ - name: 'Oranges', - quantity: 4, - price: 0.75, -}); +const firstVoucherCode = null // Do not edit this exported object module.exports = { basket: basket, numberOfVoucherCodes: numberOfVoucherCodes, - firstVoucherCode: firstVoucherCode, -}; + firstVoucherCode: firstVoucherCode +} diff --git a/src/data-types/strings.js b/src/data-types/strings.js index db3dea75..a8eb8c5b 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 = `${firstName} ${secondName}`; +const fullName = null // Set this variable to the 10th character of the alphabet variable -const tenthCharacterOfAlphabet = alphabet.charAt(9); +const tenthCharacterOfAlphabet = null // Set this variable by calling a method on the alphabet variable to transform it to lower case -const lowerCaseAlphabet = alphabet.toLowerCase(); +const lowerCaseAlphabet = null // Set this variable by using a property on the alphabet variable to get it's length -const numberOfLettersInAlphabet = alphabet.length; +const numberOfLettersInAlphabet = null // do not edit the exported object. module.exports = { diff --git a/src/demo/demo.js b/src/demo/demo.js index ee9026fe..9201bd8a 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 = 5 +numThree = 0 // TODO: Update the code below so that the tests pass -const numOnePlusNumTwo = 12 // Set this variable to numOne plus numTwo +const numOnePlusNumTwo = 0 // Set this variable to numOne plus numTwo // do not edit this section module.exports = { diff --git a/src/functions/calling-functions.js b/src/functions/calling-functions.js index 36a6a69b..f44038d6 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 = sayHello(); +const hello = '' // Set this variable variable to 'Hello Jane' calling the sayHelloTo function -const helloToJane = sayHelloTo('Jane'); +const helloToJane = '' // Set this variable to 'Hello Bob! Hello Bob! Hello Bob!' calling the sayHelloManyTimes function -const helloToBob3Times = sayHelloManyTimes('Bob', 3); +const helloToBob3Times = '' // do not edit below this line module.exports = { diff --git a/src/functions/creating-functions-multiple-args.js b/src/functions/creating-functions-multiple-args.js index b943690f..a437ae8a 100644 --- a/src/functions/creating-functions-multiple-args.js +++ b/src/functions/creating-functions-multiple-args.js @@ -9,13 +9,7 @@ // -1, 1 | [-1, 0, 1] // // TODO: write code below -function between(firstNum, lastNum) { - let array = []; - for (i = firstNum; i <= lastNum; 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 @@ -27,16 +21,9 @@ function between(firstNum, lastNum) { // error, 10 | ERROR!!!!!!!!!! // // TODO: write code below -function addExclamation(word, number) { - let exclamations = ''; - - for (i = 0; i < number; i++) { - exclamations += '!'; - } - return word.toUpperCase() + exclamations; -} + // change the exported value to be the name of the function you defined module.exports = { - a: between, // change undefined to be the name of the function defined to create the range of numbers (the first todo) - b: addExclamation // change undefined to be the name of the function defined to return the string with exclamations (the second todo) + 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) } diff --git a/src/functions/creating-functions.js b/src/functions/creating-functions.js index 11857778..2d2ac5e6 100644 --- a/src/functions/creating-functions.js +++ b/src/functions/creating-functions.js @@ -7,9 +7,6 @@ // 2 | 3 // // TODO: write code below -function addOne(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! @@ -21,12 +18,9 @@ function addOne(num) { // Aiyana | Hi, Aiyana :) // // TODO: write code below -function greeting(name) { - return 'Hi, ' + name.replace(name[0], name[0].toUpperCase()) + ' :)'; -} // TODO: change undefined to be the name of the functions you defined module.exports = { - a: addOne, // change undefined to be the name of the function you defined to increment a number (the first TODO) - b: greeting // change undefined to be the name of the function you defined to say hi (the second TODO) + 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) } diff --git a/src/loops/for-loop-and-arrays.js b/src/loops/for-loop-and-arrays.js index 4126bf37..682995ec 100644 --- a/src/loops/for-loop-and-arrays.js +++ b/src/loops/for-loop-and-arrays.js @@ -7,33 +7,18 @@ let word = '' // Use a for loop to set the sum variable to the sum of all the values in nums sum = 0 -for (i=0; i Date: Wed, 5 Jan 2022 16:36:19 +0000 Subject: [PATCH 07/25] assignment completed --- src/variables/assignment.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 46b9bcbbdc23d2f0d2526031e40df692aa2505b8 Mon Sep 17 00:00:00 2001 From: George T Date: Wed, 5 Jan 2022 16:46:24 +0000 Subject: [PATCH 08/25] declartion 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..01c11819 100644 --- a/src/variables/declaration.js +++ b/src/variables/declaration.js @@ -2,6 +2,8 @@ // // // 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 = '' From 307b2370a10d04c5ea859fff968d8c725ff751f9 Mon Sep 17 00:00:00 2001 From: George T Date: Wed, 5 Jan 2022 17:21:23 +0000 Subject: [PATCH 09/25] completed numbers.js --- 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 745efb54ea9976c1b8e30a6b258ecdbaa73963c4 Mon Sep 17 00:00:00 2001 From: George T Date: Wed, 5 Jan 2022 17:30:31 +0000 Subject: [PATCH 10/25] completed strings --- spec/data-types/strings.spec.js | 2 +- src/data-types/strings.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/data-types/strings.spec.js b/spec/data-types/strings.spec.js index ca10ec96..90bdf2b7 100644 --- a/spec/data-types/strings.spec.js +++ b/spec/data-types/strings.spec.js @@ -1,7 +1,7 @@ const { a, b, c, d } = require('../../src/data-types/strings') describe('Strings:', () => { - it('fullName is Jame Smith', () => { + it('fullName is Jane Smith', () => { expect(a).toEqual('Jane Smith') }) diff --git a/src/data-types/strings.js b/src/data-types/strings.js index a8eb8c5b..26ef9a44 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[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 c1f3c4f1a7a759114d1e7318c6c5d96549434b1b Mon Sep 17 00:00:00 2001 From: George T Date: Wed, 5 Jan 2022 17:51:36 +0000 Subject: [PATCH 11/25] completed accessing-elements --- src/data-types/arrays/README.md | 2 +- src/data-types/arrays/accessing-elements.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/data-types/arrays/README.md b/src/data-types/arrays/README.md index 8182b2eb..061f3e42 100644 --- a/src/data-types/arrays/README.md +++ b/src/data-types/arrays/README.md @@ -1,7 +1,7 @@ # Arrays Variables allow us to store a single value. An `age` variable is a single number, a `name` variable is a single string. But what if we wanted to have not one, but several names stored for later? Or what if we wanted to store a list of tweets or a list of items in a shopping cart? -**Arrays** allow us to do this. Array's are a single data type used to represent a list of things. +**Arrays** allow us to do this. Arrays are a single data type used to represent a list of things. > 👨‍💻 Run these examples in your REPL as you read along! 👨‍💻 diff --git a/src/data-types/arrays/accessing-elements.js b/src/data-types/arrays/accessing-elements.js index 374a19bb..bfa479e8 100644 --- a/src/data-types/arrays/accessing-elements.js +++ b/src/data-types/arrays/accessing-elements.js @@ -4,16 +4,16 @@ const cities = ['London', 'Shanghai', 'New York', 'Delhi', 'Kuala Lumpur'] // TODO: write code to pass the tests // Set names equal to an array containing 'Bob', 'Jane', 'Joanna' in that order -const names = null +const names = ['Bob', 'Jane', 'Joanna'] // Set fourthCity to the 4th element in the cities array -const fourthCity = '' +const fourthCity = cities[3] // Set firstCity to the 1st element in the cities array -const firstCity = '' +const firstCity = cities[0] // Set lengthOfCitiesArray to the length of the cities array -const lengthOfCitiesArray = NaN +const lengthOfCitiesArray = cities.length // Do not edit this exported object module.exports = { From e3450319506a8d87b259a2921970cfa31b96c5e2 Mon Sep 17 00:00:00 2001 From: George T Date: Wed, 5 Jan 2022 17:56:53 +0000 Subject: [PATCH 12/25] completed adding-removing-elements --- .../arrays/adding-removing-elements.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/data-types/arrays/adding-removing-elements.js b/src/data-types/arrays/adding-removing-elements.js index 69e559e8..7ae95183 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) +// Use an array method to remove 'Jordan' 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.undefined +const pear = fruits.pop('pear') // Do not edit this exported object module.exports = { From 5a74ed9dd4feb7b28542ab3dfe3566b7dcdf9c2c Mon Sep 17 00:00:00 2001 From: George T Date: Wed, 5 Jan 2022 19:53:44 +0000 Subject: [PATCH 13/25] completed creating-objects.js --- src/data-types/objects/creating-objects.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/data-types/objects/creating-objects.js b/src/data-types/objects/creating-objects.js index 1939e6b0..d113edb7 100644 --- a/src/data-types/objects/creating-objects.js +++ b/src/data-types/objects/creating-objects.js @@ -1,7 +1,14 @@ // 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 35aebd1e5845f7f53fe1af468e01761a9852489d Mon Sep 17 00:00:00 2001 From: George T Date: Wed, 5 Jan 2022 20:03:40 +0000 Subject: [PATCH 14/25] completed object-keys.js --- 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..573b1db5 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'] = isbn13 + +delete book.dimensions + +delete book.isbn.asin // Do not edit this exported object module.exports = { From 4852db747b8aa95c8638c4f43bcbfcacfa2785a7 Mon Sep 17 00:00:00 2001 From: George T Date: Wed, 5 Jan 2022 20:35:34 +0000 Subject: [PATCH 15/25] completed objects-and-arrays --- src/data-types/objects/objects-and-arrays.js | 10 +++++++--- 1 file changed, 7 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..7835b25b 100644 --- a/src/data-types/objects/objects-and-arrays.js +++ b/src/data-types/objects/objects-and-arrays.js @@ -22,10 +22,14 @@ 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 +// Set this variable to the first element of the baskets voucher codes array +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 c64675b7bd5820e3dc68b18514fb280be6ede2b0 Mon Sep 17 00:00:00 2001 From: George T Date: Wed, 5 Jan 2022 21:07:39 +0000 Subject: [PATCH 16/25] completed for-loop-and-arrays --- src/loops/example.js | 2 +- src/loops/for-loop-and-arrays.js | 4 +++- src/loops/for-loop-basic.js | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/loops/example.js b/src/loops/example.js index eee24f17..6c9c7ac9 100644 --- a/src/loops/example.js +++ b/src/loops/example.js @@ -8,7 +8,7 @@ for (let i = 1; i < 6; i++) { nums.push(i) } -// TODO: Write a for loop to add the all but the last number of nums to the nums2 array +// TODO: Write a for loop to add the all but the last number of nums2 to the nums3 array for (let i = 0; i < nums2.length - 1; i++) { nums3.push(nums2[i]) } diff --git a/src/loops/for-loop-and-arrays.js b/src/loops/for-loop-and-arrays.js index 682995ec..21b5d6fa 100644 --- a/src/loops/for-loop-and-arrays.js +++ b/src/loops/for-loop-and-arrays.js @@ -6,7 +6,9 @@ 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-1; i--) { + countdown.push(i) +} // do not change below this line module.exports = { From 6a79224495a0b7527e5f68b61680fad5a701529a Mon Sep 17 00:00:00 2001 From: George T Date: Wed, 5 Jan 2022 21:31:00 +0000 Subject: [PATCH 17/25] completed for-loop-and-arrays --- src/loops/for-loop-and-arrays.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/loops/for-loop-and-arrays.js b/src/loops/for-loop-and-arrays.js index 21b5d6fa..20bd8083 100644 --- a/src/loops/for-loop-and-arrays.js +++ b/src/loops/for-loop-and-arrays.js @@ -13,15 +13,28 @@ for (let i=0; i Date: Thu, 6 Jan 2022 09:51:07 +0000 Subject: [PATCH 18/25] completed calling-functions --- src/functions/calling-functions.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/functions/calling-functions.js b/src/functions/calling-functions.js index f44038d6..4cc96add 100644 --- a/src/functions/calling-functions.js +++ b/src/functions/calling-functions.js @@ -19,13 +19,13 @@ function sayHelloManyTimes (name, times) { // TODO: Add and update code here to make the tests pass // Set this variable to 'Hello' by calling the sayHello function -const hello = '' +const hello = sayHello() // Set this variable variable to 'Hello Jane' calling the sayHelloTo function -const helloToJane = '' +const helloToJane = sayHelloTo('Jane') // Set this variable to 'Hello Bob! Hello Bob! Hello Bob!' calling the sayHelloManyTimes function -const helloToBob3Times = '' +const helloToBob3Times = sayHelloManyTimes('Bob', 3) // do not edit below this line module.exports = { From 4446d84dbe819cc361edc64ab574f4cff9cc6e0e Mon Sep 17 00:00:00 2001 From: George T Date: Thu, 6 Jan 2022 10:04:02 +0000 Subject: [PATCH 19/25] completed creating-functions --- 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..c40337b8 100644 --- a/src/functions/creating-functions.js +++ b/src/functions/creating-functions.js @@ -7,6 +7,9 @@ // 2 | 3 // // TODO: write code below +function increment(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 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: increment, // 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 48ef6893c812393e145ac78ba66fadf3ef549c31 Mon Sep 17 00:00:00 2001 From: George T Date: Thu, 6 Jan 2022 10:42:17 +0000 Subject: [PATCH 20/25] completed creating-functions-multiple-args --- .../creating-functions-multiple-args.js | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/functions/creating-functions-multiple-args.js b/src/functions/creating-functions-multiple-args.js index a437ae8a..a05e7a01 100644 --- a/src/functions/creating-functions-multiple-args.js +++ b/src/functions/creating-functions-multiple-args.js @@ -9,6 +9,16 @@ // -1, 1 | [-1, 0, 1] // // TODO: write code below + + + function numbers(lower, upper) { + let z = [] + + for (let i=lower; i<=upper; i++) { + z.push(i) + } + return z + } // 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 @@ -21,9 +31,19 @@ // error, 10 | ERROR!!!!!!!!!! // // TODO: write code below + + + function exclamation(a, b) { + let marks = '' + + for (let i=0; i Date: Thu, 6 Jan 2022 10:56:05 +0000 Subject: [PATCH 21/25] completed boolean-conditions --- 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 70b623d4..4922cdfa 100644 --- a/src/conditional-flow/boolean-conditions.js +++ b/src/conditional-flow/boolean-conditions.js @@ -2,10 +2,14 @@ // "Well done, you passed!" if the value is true, or "Sorry, try again" // if the value is false. function getResult (didPass) { - + if (didPass === true) { + 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 From 219678d9f5608376abdf555829713fe9009e5bb7 Mon Sep 17 00:00:00 2001 From: George T Date: Thu, 6 Jan 2022 11:06:42 +0000 Subject: [PATCH 22/25] Completed multiple-conditions --- src/conditional-flow/multiple-conditions.js | 50 ++++++++++++++++----- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/conditional-flow/multiple-conditions.js b/src/conditional-flow/multiple-conditions.js index 80420abf..4312679d 100644 --- a/src/conditional-flow/multiple-conditions.js +++ b/src/conditional-flow/multiple-conditions.js @@ -1,19 +1,21 @@ // This function should return true if num is greater // than or equal to lower AND less than or equal to upper. // Implement this with a single condition. -function isInRange (num, lower, upper) { - +function isInRange(num, lower, upper) { // TODO: write code in this function body to pass the tests - + 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) { - +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 @@ -28,13 +30,41 @@ function isHelloOrGoodbye (val1) { // 5-12 | Child // 13-19 | Teenager // 20+ | Adult -function getAgeDescription (age) { - +function getAgeDescription(age) { // TODO: write code in this function body to pass the tests + switch (age) { + case 0: + return "Baby"; + case 1: + case 2: + case 3: + case 4: + return "Toddler"; + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + return "Child"; + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: + return "Teenager"; + break; + default: + return "Adult" + } } module.exports = { a: isInRange, b: isHelloOrGoodbye, - c: getAgeDescription -} + c: getAgeDescription, +}; From 069981ea23d30c064bad4b8ca1588be4b79fb4fc Mon Sep 17 00:00:00 2001 From: George T Date: Thu, 6 Jan 2022 11:39:20 +0000 Subject: [PATCH 23/25] completed numeric-conditions --- src/conditional-flow/numeric-conditions.js | 18 +++++++++++++++++- src/variables/declaration.js | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/conditional-flow/numeric-conditions.js b/src/conditional-flow/numeric-conditions.js index 0f6656a5..a3b6b819 100644 --- a/src/conditional-flow/numeric-conditions.js +++ b/src/conditional-flow/numeric-conditions.js @@ -4,6 +4,10 @@ function isArrayEmpty (array) { // TODO: write code in this function body to pass the tests + if (array.length === 0){ + return true + } + else return false } @@ -11,6 +15,10 @@ 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 } @@ -18,7 +26,15 @@ function isGreaterThan (num1, num2) { function findLowest (nums) { // TODO: write code in this function body to pass the tests - + let i = 0 + let lowest = nums[i] + + for (let i=0; i nums[i]) { + lowest = nums[i] + } + } + return lowest } module.exports = { diff --git a/src/variables/declaration.js b/src/variables/declaration.js index 01c11819..c2f2493f 100644 --- a/src/variables/declaration.js +++ b/src/variables/declaration.js @@ -2,7 +2,7 @@ // // // TODO: Declare the variables firstName and age so that the tests pass -let firstName = Jane +let firstName = 'Jane' const age = 35 // do not edit below this line From 95f83bb40f6772bc022ec53b5b219344944f2285 Mon Sep 17 00:00:00 2001 From: George T Date: Thu, 6 Jan 2022 12:02:17 +0000 Subject: [PATCH 24/25] complete string-conditions --- src/conditional-flow/string-conditions.js | 91 +++++++++++++++++++---- 1 file changed, 75 insertions(+), 16 deletions(-) diff --git a/src/conditional-flow/string-conditions.js b/src/conditional-flow/string-conditions.js index d91bfaf0..c324039b 100644 --- a/src/conditional-flow/string-conditions.js +++ b/src/conditional-flow/string-conditions.js @@ -1,41 +1,78 @@ // This function should return true if the passed string is equal to "Hello" -function isHello (val1) { - +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) { - +function isNotHello(val1) { + if (val1 !== 'Hello') { + return true; + } + else { + 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) { - +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 - } // This function should return true if the string passed in the function's first // argument has an odd number of vowels -function hasOddNumberVowels (val1) { +function hasOddNumberVowels(val1) { + let count = 0; + let valLower = val1.toLowerCase(); + + for (i = 0; i < valLower.length; i++) { + if ( + valLower[i] == 'a' || valLower[i] == 'i' || + valLower[i] == 'e' || valLower[i] == 'o' || + valLower[i] == 'u' + ) { + count++; + } + } + + if (count % 2 === 1) { + return true; + } + else { + return false; + } // TODO: write code in this function body to pass the tests - } // 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) { +function getMiddleLetter(val1) { // TODO: write code in this function body to pass the tests - + if (val1.length % 2 === 1) { + let oddChar = Math.floor(val1.length / 2); + return val1[oddChar]; + } + else { + let evenChar = val1.length / 2; + return val1[evenChar - 1] + val1[evenChar]; + } } // This function should return the name of the season for the provided @@ -47,9 +84,31 @@ function getMiddleLetter (val1) { // Summer - June to August // Autumn - September to November // Winter - December to February -function seasonForMonth (monthName) { +function seasonForMonth(monthName) { // TODO: write code in this function body to pass the tests + // let inputMonth; + + switch (monthName) { + case 'March': + case 'April': + case 'May': + return 'Spring'; + case 'June': + case 'July': + case 'August': + return 'Summer'; + case 'September': + case 'October': + case 'November': + return 'Autumn'; + case 'December': + case 'January': + case 'February': + return 'Winter'; + default: + return ''; + } } module.exports = { @@ -58,5 +117,5 @@ module.exports = { c: isLongerThan, d: hasOddNumberVowels, e: getMiddleLetter, - f: seasonForMonth -} + f: seasonForMonth, +}; \ No newline at end of file From 2e073afd9b3516a1a784194c512c33c810f6f475 Mon Sep 17 00:00:00 2001 From: George T Date: Thu, 6 Jan 2022 12:04:07 +0000 Subject: [PATCH 25/25] js-fundamentals complete II --- 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..ee9026fe 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 = 12 // Set this variable to numOne plus numTwo // do not edit this section module.exports = {