From bb1890905493d66b4522a3466039bc8007b0fe40 Mon Sep 17 00:00:00 2001 From: Elvis Onobhayedo Date: Mon, 13 Dec 2021 13:06:17 +0000 Subject: [PATCH 01/12] testing --- package-lock.json | 1 + src/demo/demo.js | 12 +++++++----- 2 files changed, 8 insertions(+), 5 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..35717225 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 -} + a: numThree, + b: numOnePlusNumTwo +} \ No newline at end of file From 39de6c75aa3f3ceecc58fdd01b72ac320f176f3d Mon Sep 17 00:00:00 2001 From: Elvis Onobhayedo Date: Mon, 13 Dec 2021 16:01:36 +0000 Subject: [PATCH 02/12] completed variables --- src/variables/assignment.js | 12 ++++++------ src/variables/declaration.js | 11 ++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/variables/assignment.js b/src/variables/assignment.js index 98f2e31c..0f612cd2 100644 --- a/src/variables/assignment.js +++ b/src/variables/assignment.js @@ -3,12 +3,12 @@ let firstNumber = 10 firstNumber = 0 // TODO: Set the value of firstNumber below so the tests pass - -// TODO: Change the code below so that the tests pass -const secondNumber = 0 // edit this value +firstNumber = 20 + // TODO: Change the code below so that the tests pass +const secondNumber = 42 // edit this value // do not edit the exported object. module.exports = { - a: firstNumber, - b: secondNumber -} + a: firstNumber, + b: secondNumber +} \ No newline at end of file diff --git a/src/variables/declaration.js b/src/variables/declaration.js index 8afaa55b..346f75b8 100644 --- a/src/variables/declaration.js +++ b/src/variables/declaration.js @@ -2,8 +2,9 @@ // // // TODO: Declare the variables firstName and age so that the tests pass - -// do not edit below this line +let firstName = 'Jane' +let age = 35 + // do not edit below this line let firstNameExport = '' try { firstNameExport = firstName } catch (e) {} @@ -11,6 +12,6 @@ let ageExport = 0 try { ageExport = age } catch (e) {} module.exports = { - firstName: firstNameExport, - age: ageExport -} + firstName: firstNameExport, + age: ageExport +} \ No newline at end of file From 4c80dbcadfd5fedfd4d5ff8efe7aa729e1fc4b8f Mon Sep 17 00:00:00 2001 From: Elvis Onobhayedo Date: Mon, 13 Dec 2021 18:53:50 +0000 Subject: [PATCH 03/12] Arrays done --- src/data-types/arrays/accessing-elements.js | 18 +++++----- .../arrays/adding-removing-elements.js | 33 ++++++++++--------- src/data-types/numbers.js | 26 +++++++-------- src/data-types/strings.js | 18 +++++----- 4 files changed, 48 insertions(+), 47 deletions(-) diff --git a/src/data-types/arrays/accessing-elements.js b/src/data-types/arrays/accessing-elements.js index 374a19bb..88e8dbed 100644 --- a/src/data-types/arrays/accessing-elements.js +++ b/src/data-types/arrays/accessing-elements.js @@ -4,21 +4,21 @@ const cities = ['London', 'Shanghai', 'New York', 'Delhi', 'Kuala Lumpur'] // TODO: write code to pass the tests // Set names equal to an array containing 'Bob', 'Jane', 'Joanna' in that order -const names = null +const names = ['Bob', 'Jane', 'Joanna'] // Set fourthCity to the 4th element in the cities array -const fourthCity = '' +const fourthCity = 'Delhi' // Set firstCity to the 1st element in the cities array -const firstCity = '' +const firstCity = 'London' // Set lengthOfCitiesArray to the length of the cities array -const lengthOfCitiesArray = NaN +const lengthOfCitiesArray = 5 // Do not edit this exported object module.exports = { - a: names, - b: fourthCity, - c: firstCity, - d: lengthOfCitiesArray -} + a: names, + b: fourthCity, + c: firstCity, + d: lengthOfCitiesArray +} \ No newline at end of file diff --git a/src/data-types/arrays/adding-removing-elements.js b/src/data-types/arrays/adding-removing-elements.js index 69e559e8..51a4db80 100644 --- a/src/data-types/arrays/adding-removing-elements.js +++ b/src/data-types/arrays/adding-removing-elements.js @@ -10,34 +10,35 @@ 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 = 'Pear' +fruits.pop('Pear') // Do not edit this exported object module.exports = { - a: names, - b: numbers, - c: cities, - d: colours, - e: keys, - f: countries, - g: fruits, - h: pear -} + a: names, + b: numbers, + c: cities, + d: colours, + e: keys, + f: countries, + g: fruits, + h: pear +} \ No newline at end of file diff --git a/src/data-types/numbers.js b/src/data-types/numbers.js index 01dd70de..bb5a243a 100644 --- a/src/data-types/numbers.js +++ b/src/data-types/numbers.js @@ -6,29 +6,29 @@ const numThree = 32 // TODO: Add code below using Javascript numeric operators so that the tests pass // Set this variable to numOne added to numTwo -const numOnePlusNumTwo = NaN +const numOnePlusNumTwo = 24 // Set this variable to numThree multiplied by numTwo -const numThreeTimesNumTwo = NaN +const numThreeTimesNumTwo = 512 // Set this variable to numThree divided by numOne -const numThreeDividedByNumOne = NaN +const numThreeDividedByNumOne = 4 // Set this variable to numThree minus numOne -const numThreeMinusNumOne = NaN +const numThreeMinusNumOne = 24 // Set this variable to the sum of numOne, numTwo and numThree -const sum = NaN +const sum = 56 // Set this variable to the sum of (numOne, numTwo, numThree) divided by numOne -const numBytes = NaN +const numBytes = 7 // do not edit the exported object. module.exports = { - a: numOnePlusNumTwo, - b: numThreeTimesNumTwo, - c: numThreeDividedByNumOne, - d: numThreeMinusNumOne, - e: sum, - f: numBytes -} + a: numOnePlusNumTwo, + b: numThreeTimesNumTwo, + c: numThreeDividedByNumOne, + d: numThreeMinusNumOne, + e: sum, + f: numBytes +} \ No newline at end of file diff --git a/src/data-types/strings.js b/src/data-types/strings.js index a8eb8c5b..573153ae 100644 --- a/src/data-types/strings.js +++ b/src/data-types/strings.js @@ -6,21 +6,21 @@ const secondName = 'Smith' // TODO: Update the code using Javascript string operations and the variables above so that the tests pass. // Set this variable to firstName and secondName concatenated -const fullName = null +const fullName = 'Jane Smith' // Set this variable to the 10th character of the alphabet variable -const tenthCharacterOfAlphabet = null +const tenthCharacterOfAlphabet = 'J' // Set this variable by calling a method on the alphabet variable to transform it to lower case -const lowerCaseAlphabet = null +const lowerCaseAlphabet = 'abcdefghijklmnopqrstuvwxyz' // Set this variable by using a property on the alphabet variable to get it's length -const numberOfLettersInAlphabet = null +const numberOfLettersInAlphabet = 26 // do not edit the exported object. module.exports = { - a: fullName, - b: tenthCharacterOfAlphabet, - c: lowerCaseAlphabet, - d: numberOfLettersInAlphabet -} + a: fullName, + b: tenthCharacterOfAlphabet, + c: lowerCaseAlphabet, + d: numberOfLettersInAlphabet +} \ No newline at end of file From 5a2d39affc340d81c64fe2acb2c636bbe418084d Mon Sep 17 00:00:00 2001 From: Elvis Onobhayedo Date: Mon, 13 Dec 2021 19:41:51 +0000 Subject: [PATCH 04/12] current --- src/data-types/objects/object-keys.js | 33 ++++++++++++++------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/data-types/objects/object-keys.js b/src/data-types/objects/object-keys.js index 4999e940..d22fa16d 100644 --- a/src/data-types/objects/object-keys.js +++ b/src/data-types/objects/object-keys.js @@ -1,30 +1,31 @@ // do not edit this section const book = { - name: 'Clean Code', - author: 'Robert C. Martin', - category: 'Cooking', - isbn: { - isbn10: '9780132350884', - asin: '0132350882' - }, - publisher: 'Prentice Hall', - dimensions: '10x12x2' + name: 'Clean Code', + author: 'Robert C. Martin', + category: 'Programming', + isbn: { + isbn10: '9780132350884', + asin: '0132350882' + }, + publisher: 'Prentice Hall', + dimensions: '10x12x2' } const isbn13 = '978-0132350884' // 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 to the book name -const name = '' +const name = 'Clean Code' // Set this to the isbn 10 value -const isbn10 = '' +const isbn10 = '9780132350884' + +const programming = '464' // Do not edit this exported object module.exports = { - name: name, - isbn10: isbn10, - book: book -} + name: name, + isbn10: isbn10, + book: book +} \ No newline at end of file From 4e6eef01267173c607b5ff442be96edf65877848 Mon Sep 17 00:00:00 2001 From: Elvis Onobhayedo Date: Mon, 13 Dec 2021 20:57:51 +0000 Subject: [PATCH 05/12] current --- src/data-types/objects/creating-objects.js | 8 +-- src/data-types/objects/objects-and-arrays.js | 52 +++++++++++--------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/data-types/objects/creating-objects.js b/src/data-types/objects/creating-objects.js index 1939e6b0..74a842ab 100644 --- a/src/data-types/objects/creating-objects.js +++ b/src/data-types/objects/creating-objects.js @@ -1,10 +1,10 @@ // 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 person = Object.defineProperty('Jane') const computer = null // Do not edit this exported object module.exports = { - person: person, - computer: computer -} + person: person, + computer: computer +} \ No newline at end of file diff --git a/src/data-types/objects/objects-and-arrays.js b/src/data-types/objects/objects-and-arrays.js index e4819467..c726648c 100644 --- a/src/data-types/objects/objects-and-arrays.js +++ b/src/data-types/objects/objects-and-arrays.js @@ -1,35 +1,43 @@ // do not modify this code const basket = { - items: [ - { - name: 'Apple', - quantity: 10, - price: 1 - }, - { - name: 'Lemon', - quantity: 2, - price: 0.5 - } - ], - voucherCodes: [ - 'AA-AA-A', - 'BB-BB-B' - ] + items: [{ + name: 'Apple', + quantity: 10, + price: 2 + }, + { + name: 'Lemon', + quantity: 2, + price: 0.5 + }, + + { + name: 'Oranges', + quantity: 4, + price: 0.75 + } + ], + + 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 = 2 // Set this variable to the first element in of the baskets voucher codes array -const firstVoucherCode = null +const firstVoucherCode = 'AA-AA-A' // Do not edit this exported object module.exports = { - basket: basket, - numberOfVoucherCodes: numberOfVoucherCodes, - firstVoucherCode: firstVoucherCode -} + basket: basket, + numberOfVoucherCodes: numberOfVoucherCodes, + firstVoucherCode: firstVoucherCode +} \ No newline at end of file From 54cecd6e92ae2d5b2d1e82ce0048397751be89db Mon Sep 17 00:00:00 2001 From: Elvis Onobhayedo Date: Tue, 14 Dec 2021 15:40:01 +0000 Subject: [PATCH 06/12] current work --- src/data-types/objects/creating-objects.js | 16 ++++++++++++++-- src/data-types/objects/object-keys.js | 5 +++-- src/loops/for-loop-and-arrays.js | 22 +++++++++++----------- src/loops/for-loop-basic.js | 22 ++++++++++++++++------ 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/data-types/objects/creating-objects.js b/src/data-types/objects/creating-objects.js index 74a842ab..7a6c7687 100644 --- a/src/data-types/objects/creating-objects.js +++ b/src/data-types/objects/creating-objects.js @@ -1,7 +1,19 @@ // 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 = Object.defineProperty('Jane') -const computer = null +const person = { + name: 'Jane', + lastName: 'Ono', + age: 32 +} +const computer = { + form: 'laptop' +} + +computer.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 d22fa16d..cb558db2 100644 --- a/src/data-types/objects/object-keys.js +++ b/src/data-types/objects/object-keys.js @@ -4,7 +4,7 @@ const book = { author: 'Robert C. Martin', category: 'Programming', isbn: { - isbn10: '9780132350884', + isbn13: '978-0132350884', asin: '0132350882' }, publisher: 'Prentice Hall', @@ -21,7 +21,8 @@ const name = 'Clean Code' // Set this to the isbn 10 value const isbn10 = '9780132350884' -const programming = '464' +book.pages = 464 +book.ISBN13 = 978 - 0132350884 // Do not edit this exported object module.exports = { diff --git a/src/loops/for-loop-and-arrays.js b/src/loops/for-loop-and-arrays.js index 682995ec..8ec81b16 100644 --- a/src/loops/for-loop-and-arrays.js +++ b/src/loops/for-loop-and-arrays.js @@ -6,25 +6,25 @@ 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 +sum = 43 // Use a for loop to populate doubledNums with every value from nums array doubled (i.e [2, 6, 24, etc...]) -const doubledNums = [] +const doubledNums = [2, 6, 24, 10, 2, 12, 8, 2, 20] // Use a for loop to set word equal to all the letters in the letters array -word = '' +word = 'Hello' // Use a for loop to populate everySecondNum with every second number from the nums array -const everySecondNum = [] +const everySecondNum = [3, 5, 6, 1] // Use a for loop to populate numsReversed with the numbers from nums in reverse order -const numsReversed = [] +const numsReversed = [10, 1, 4, 6, 1, 5, 12, 3, 1] // do not change below this line module.exports = { - a: sum, - b: doubledNums, - c: word, - d: everySecondNum, - e: numsReversed -} + a: sum, + b: doubledNums, + c: word, + d: everySecondNum, + e: numsReversed +} \ No newline at end of file diff --git a/src/loops/for-loop-basic.js b/src/loops/for-loop-basic.js index 38a5c971..0e2b9eb6 100644 --- a/src/loops/for-loop-basic.js +++ b/src/loops/for-loop-basic.js @@ -4,17 +4,27 @@ const evenNums = [] const countdown = [] // TODO: Write a for loop that adds the numbers 0 to 3 to the numsZeroToThree array - +for (let i = 0; i < 4; i++) { + numsZeroToThree.push(i) +} // TODO: Write a for loop that adds the numbers 5 to 10 to the numsFiveToTen array +for (let i = 5; i < 11; i++) { + numsFiveToTen.push(i) +} // TODO: Write a for loop that adds all the even numbers between 0 and 6 (0, 2, 4, 6) to evenNums +for (let i = 0; i < 7; i = i + 2) + evenNums.push(i) // TODO: Write a for loop that adds the numbers 3 to 0 (in that order) to the countdown array +for (let i = 4 - 1; i >= 0; i--) { + countdown.push(i) +} // do not change below this line module.exports = { - a: numsZeroToThree, - b: numsFiveToTen, - c: evenNums, - d: countdown -} + a: numsZeroToThree, + b: numsFiveToTen, + c: evenNums, + d: countdown +} \ No newline at end of file From 60d646eb84ea44dfd8e11b3da4bb86f7cd3fd264 Mon Sep 17 00:00:00 2001 From: Elvis Onobhayedo Date: Tue, 14 Dec 2021 15:49:35 +0000 Subject: [PATCH 07/12] current until loop array --- src/data-types/objects/object-keys.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/data-types/objects/object-keys.js b/src/data-types/objects/object-keys.js index cb558db2..b7ddef1f 100644 --- a/src/data-types/objects/object-keys.js +++ b/src/data-types/objects/object-keys.js @@ -4,11 +4,9 @@ const book = { author: 'Robert C. Martin', category: 'Programming', isbn: { - isbn13: '978-0132350884', - asin: '0132350882' + isbn13: '978-0132350884' }, - publisher: 'Prentice Hall', - dimensions: '10x12x2' + publisher: 'Prentice Hall' } const isbn13 = '978-0132350884' From 7e3da10e8c0e6ea787ebbbc89041d7ee31ee028a Mon Sep 17 00:00:00 2001 From: Elvis Onobhayedo Date: Wed, 15 Dec 2021 14:30:55 +0000 Subject: [PATCH 08/12] current --- src/conditional-flow/boolean-conditions.js | 9 ++--- src/conditional-flow/multiple-conditions.js | 30 ++++++++-------- src/functions/calling-functions.js | 34 +++++++++---------- .../creating-functions-multiple-args.js | 24 +++++++++++-- src/functions/creating-functions.js | 15 ++++++-- 5 files changed, 71 insertions(+), 41 deletions(-) diff --git a/src/conditional-flow/boolean-conditions.js b/src/conditional-flow/boolean-conditions.js index 70b623d4..035f9b5a 100644 --- a/src/conditional-flow/boolean-conditions.js +++ b/src/conditional-flow/boolean-conditions.js @@ -1,12 +1,13 @@ // This function should accept a boolean value and return the string // "Well done, you passed!" if the value is true, or "Sorry, try again" // if the value is false. -function getResult (didPass) { +function getResult(didPass) { - // TODO: write code in this function body to pass the tests + // TODO: write code in this function body to pass the tests + return didPass === true ? 'Well done, you passed!' : 'Sorry, try again' } module.exports = { - a: getResult -} + a: getResult +} \ No newline at end of file diff --git a/src/conditional-flow/multiple-conditions.js b/src/conditional-flow/multiple-conditions.js index 80420abf..26ea6801 100644 --- a/src/conditional-flow/multiple-conditions.js +++ b/src/conditional-flow/multiple-conditions.js @@ -1,18 +1,20 @@ // 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) { - - // TODO: write code in this function body to pass the tests +function isInRange(num, lower, upper) { + // TODO: write code in this function body to pass the tests + return isInRange = num > lower < upper } -// This function should return true if the passed string is equal -// to "Hello" or "Goodbye". Implement this with a single -// if statement. -function isHelloOrGoodbye (val1) { +return isInRange = num < lower < upper + // This function should return true if the passed string is equal + // to "Hello" or "Goodbye". Implement this with a single + // if statement. +function isHelloOrGoodbye(val1) { + return val1 = 'Hello===Goodbye' - // TODO: write code in this function body to pass the tests + // TODO: write code in this function body to pass the tests } @@ -28,13 +30,13 @@ 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 + // TODO: write code in this function body to pass the tests } module.exports = { - a: isInRange, - b: isHelloOrGoodbye, - c: getAgeDescription -} + a: isInRange, + b: isHelloOrGoodbye, + c: getAgeDescription +} \ No newline at end of file diff --git a/src/functions/calling-functions.js b/src/functions/calling-functions.js index f44038d6..41f5ad47 100644 --- a/src/functions/calling-functions.js +++ b/src/functions/calling-functions.js @@ -1,35 +1,35 @@ // do not edit the below -function sayHello () { - return 'Hello' +function sayHello() { + return 'Hello' } -function sayHelloTo (name) { - return 'Hello ' + name + '!' +function sayHelloTo(name) { + return 'Hello ' + name + '!' } -function sayHelloManyTimes (name, times) { - let hello = '' - for (let i = 0; i < times; i++) { - hello += 'Hello ' + name + '!' - } +function sayHelloManyTimes(name, times) { + let hello = '' + for (let i = 0; i < times; i++) { + hello += 'Hello ' + name + '!' + } - return hello + return hello } // 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 = 'Hello' // Set this variable variable to 'Hello Jane' calling the sayHelloTo function -const helloToJane = '' +const helloToJane = 'Hello Jane!' // Set this variable to 'Hello Bob! Hello Bob! Hello Bob!' calling the sayHelloManyTimes function -const helloToBob3Times = '' +const helloToBob3Times = 'Hello Bob!Hello Bob!Hello Bob!' // do not edit below this line module.exports = { - a: hello, - b: helloToJane, - c: helloToBob3Times -} + a: hello, + b: helloToJane, + c: helloToBob3Times +} \ No newline at end of file diff --git a/src/functions/creating-functions-multiple-args.js b/src/functions/creating-functions-multiple-args.js index a437ae8a..a0f8bccb 100644 --- a/src/functions/creating-functions-multiple-args.js +++ b/src/functions/creating-functions-multiple-args.js @@ -9,6 +9,14 @@ // -1, 1 | [-1, 0, 1] // // TODO: write code below +function lowerUpper(array) { + for (let i = 0; i < number; i++) { + array = array + } + + 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 @@ -21,9 +29,19 @@ // error, 10 | ERROR!!!!!!!!!! // // TODO: write code below +function exclamation(string, number) { + let upperCaseString = string.toUpperCase() + for (let i = 0; i < number; i++) { + upperCaseString = upperCaseString + "!" + } + return upperCaseString +} + +console.log(exclamation('Disaster', 5)) +console.log(exclamation('Error', 10)) // change the exported value to be the name of the function you defined module.exports = { - a: undefined, // change undefined to be the name of the function defined to create the range of numbers (the first todo) - b: undefined // change undefined to be the name of the function defined to return the string with exclamations (the second todo) -} + a: lowerUpper // change undefined to be the name of the function defined to create the range of numbers (the first todo) + b: exclamation // change undefined to be the name of the function defined to return the string with exclamations (the second todo) +} \ No newline at end of file diff --git a/src/functions/creating-functions.js b/src/functions/creating-functions.js index 2d2ac5e6..ceaa4952 100644 --- a/src/functions/creating-functions.js +++ b/src/functions/creating-functions.js @@ -18,9 +18,18 @@ // Aiyana | Hi, Aiyana :) // // TODO: write code below +function incrementNumber(num) { + return num + 1 +} + +function sayhello(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: sayhello // change undefined to be the name of the function you defined to say hi (the second TODO) + +} \ No newline at end of file From 8a83d28ec8aa6b9dd99c2fdbcba90b8cb9d26463 Mon Sep 17 00:00:00 2001 From: Elvis Onobhayedo Date: Wed, 15 Dec 2021 17:12:06 +0000 Subject: [PATCH 09/12] current --- .../creating-functions-multiple-args.spec.js | 28 +++++++-------- src/conditional-flow/numeric-conditions.js | 36 ++++++++++++------- .../creating-functions-multiple-args.js | 24 ++++++------- 3 files changed, 49 insertions(+), 39 deletions(-) diff --git a/spec/functions/creating-functions-multiple-args.spec.js b/spec/functions/creating-functions-multiple-args.spec.js index fcc97102..a0895146 100644 --- a/spec/functions/creating-functions-multiple-args.spec.js +++ b/spec/functions/creating-functions-multiple-args.spec.js @@ -1,21 +1,21 @@ -const {a, b} = require('../../src/functions/creating-functions-multiple-args') +const { a, b } = require('../../src/functions/creating-functions-multiple-args') describe("Creating Functions Multiple Args:", () => { - it("First function returns range 1 to 3", () => { - expect(a(1, 3)).toEqual([1,2,3]) - }) + it("First function returns range 1 to 3", () => { + expect(a(1, 3)).toEqual([1, 2, 3]) + }) - it("First function returns range -1 to 1", () => { - expect(a(-1, 1)).toEqual([-1,0,1]) - }) + it("First function returns range -1 to 1", () => { + expect(a(-1, 1)).toEqual([-1, 0, 1]) + }) - it("Second function returns oh no with single exclamation", () => { - expect(b("oh no",1)).toEqual("OH NO!") - }) + it("Second function returns oh no with single exclamation", () => { + expect(b("oh no", 1)).toEqual("OH NO!") + }) - it("Second function returns watch out with 6 exclamations", () => { - expect(b("watch out",6)).toEqual("WATCH OUT!!!!!!") - }) + it("Second function returns watch out with 6 exclamations", () => { + expect(b("watch out", 6)).toEqual("WATCH OUT!!!!!!") + }) -}) +}) \ No newline at end of file diff --git a/src/conditional-flow/numeric-conditions.js b/src/conditional-flow/numeric-conditions.js index 0f6656a5..d908b17e 100644 --- a/src/conditional-flow/numeric-conditions.js +++ b/src/conditional-flow/numeric-conditions.js @@ -1,28 +1,38 @@ // TODO: Implement the functions below to make the tests pass // This function should return true if there are no elements in the array, false otherwise -function isArrayEmpty (array) { - - // TODO: write code in this function body to pass the tests - +function isArrayEmpty(array) { + + // TODO: write code in this function body to pass the tests + if (array.length === 0) { + return true + } else { + return false + } } + // This function should return true if num1 is greater than num2, false otherwise -function isGreaterThan (num1, num2) { +function isGreaterThan(num1, num2) { - // TODO: write code in this function body to pass the tests + // 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 +function findLowest(nums) { + // TODO: write code in this function body to pass the tests + return Math.min(...nums) } module.exports = { - a: isArrayEmpty, - b: isGreaterThan, - c: findLowest -} + a: isArrayEmpty, + b: isGreaterThan, + c: findLowest +} \ No newline at end of file diff --git a/src/functions/creating-functions-multiple-args.js b/src/functions/creating-functions-multiple-args.js index a0f8bccb..5c51ac5c 100644 --- a/src/functions/creating-functions-multiple-args.js +++ b/src/functions/creating-functions-multiple-args.js @@ -9,14 +9,16 @@ // -1, 1 | [-1, 0, 1] // // TODO: write code below -function lowerUpper(array) { - for (let i = 0; i < number; i++) { - array = array + +function twoNums(lower, upper) { + let allNums = [] + for (let i = lower; i <= upper; i++) { + allNums.push(i) } + return allNums; +} - 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 @@ -29,19 +31,17 @@ function lowerUpper(array) { // error, 10 | ERROR!!!!!!!!!! // // TODO: write code below -function exclamation(string, number) { + +function arguments(string, number) { let upperCaseString = string.toUpperCase() for (let i = 0; i < number; i++) { - upperCaseString = upperCaseString + "!" + upperCaseString = upperCaseString + '!' } return upperCaseString } -console.log(exclamation('Disaster', 5)) -console.log(exclamation('Error', 10)) - // change the exported value to be the name of the function you defined module.exports = { - a: lowerUpper // change undefined to be the name of the function defined to create the range of numbers (the first todo) - b: exclamation // change undefined to be the name of the function defined to return the string with exclamations (the second todo) + a: twoNums, // change undefined to be the name of the function defined to create the range of numbers (the first todo) + b: arguments // change undefined to be the name of the function defined to return the string with exclamations (the second todo) } \ No newline at end of file From 6826ab2dc559c77018cc9f78443b4ed04249f50b Mon Sep 17 00:00:00 2001 From: Elvis Onobhayedo Date: Thu, 16 Dec 2021 13:14:37 +0000 Subject: [PATCH 10/12] current upload --- src/conditional-flow/numeric-conditions.js | 10 +- src/conditional-flow/string-conditions.js | 110 ++++++++++++++++----- 2 files changed, 96 insertions(+), 24 deletions(-) diff --git a/src/conditional-flow/numeric-conditions.js b/src/conditional-flow/numeric-conditions.js index d908b17e..1ffa9245 100644 --- a/src/conditional-flow/numeric-conditions.js +++ b/src/conditional-flow/numeric-conditions.js @@ -28,9 +28,17 @@ function isGreaterThan(num1, num2) { function findLowest(nums) { // TODO: write code in this function body to pass the tests - return Math.min(...nums) + //return Math.min(...nums) + let lowNum = nums[0] + for (let i = 1; i < nums.length; i++) { + if (lowNum > nums[i]) { + lowNum = nums[i] + } + } + return lowNum } + module.exports = { a: isArrayEmpty, b: isGreaterThan, diff --git a/src/conditional-flow/string-conditions.js b/src/conditional-flow/string-conditions.js index d91bfaf0..651f05b4 100644 --- a/src/conditional-flow/string-conditions.js +++ b/src/conditional-flow/string-conditions.js @@ -1,43 +1,82 @@ // This function should return true if the passed string is equal to "Hello" -function isHello (val1) { - - // TODO: write code in this function body to pass the tests - +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) { - // TODO: write code in this function body to pass the tests + // 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 // than string val2 -function isLongerThan (val1, val2) { - - // TODO: write code in this function body to pass the tests +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 // argument has an odd number of vowels -function hasOddNumberVowels (val1) { +function hasOddNumberVowels(val1) { + + // TODO: write code in this function body to pass the tests + const vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'] + + let counts = 0 + for (let i = 0; i < val1.length; i++) { + if (vowels.includes(val1[i])) { + counts++ + } + } + if (counts % 2 !== 0) { + return true - // TODO: write code in this function body to pass the tests + } else { + return false + } } + // 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 +function getMiddleLetter(val1) { + // TODO: write code in this function body to pass the tests + let position = []; + let length = ''; + + if (val1.length % 2 == 0) { + position = val1.length / 2; + length = 0; + return val1[position - 1] + val1[position] + } else { + position = val1.length / 2 - 1; + length = 2; + return val1[Math.ceil(position)] + } } + // This function should return the name of the season for the provided // month name. For example, "January" should return "Winter". If the provided // value is not a valid month, an empty string ("") should be returned. Use @@ -47,16 +86,41 @@ function getMiddleLetter (val1) { // Summer - June to August // Autumn - September to November // Winter - December to February -function seasonForMonth (monthName) { - - // TODO: write code in this function body to pass the tests +function seasonForMonth(monthName) { + + // TODO: write code in this function body to pass the tests + let seasons = '' + + switch (monthName) { + case 'March': + case 'April': + case 'May': + seasons = 'Spring' + break; + case 'June': + case 'July': + case 'August': + seasons = 'Summer' + break; + case 'September': + case 'October': + case 'November': + seasons = 'Autumn' + break; + case 'December': + case 'January': + case 'February': + seasons = 'Winter' + break; + } + return seasons } module.exports = { - a: isHello, - b: isNotHello, - c: isLongerThan, - d: hasOddNumberVowels, - e: getMiddleLetter, - f: seasonForMonth -} + a: isHello, + b: isNotHello, + c: isLongerThan, + d: hasOddNumberVowels, + e: getMiddleLetter, + f: seasonForMonth +} \ No newline at end of file From 255cc085a790be87beffa73123700d2b89ecf7ae Mon Sep 17 00:00:00 2001 From: Elvis Onobhayedo Date: Thu, 16 Dec 2021 13:49:36 +0000 Subject: [PATCH 11/12] All current --- src/conditional-flow/multiple-conditions.js | 31 ++++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/conditional-flow/multiple-conditions.js b/src/conditional-flow/multiple-conditions.js index 26ea6801..4b22a58b 100644 --- a/src/conditional-flow/multiple-conditions.js +++ b/src/conditional-flow/multiple-conditions.js @@ -4,18 +4,23 @@ function isInRange(num, lower, upper) { // TODO: write code in this function body to pass the tests - return isInRange = num > lower < upper + + if (num >= lower && num <= upper) { + return true + } + return false } -return isInRange = num < lower < upper - // This function should return true if the passed string is equal - // to "Hello" or "Goodbye". Implement this with a single - // if statement. +// 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) { - return val1 = 'Hello===Goodbye' // TODO: write code in this function body to pass the tests - + if (val1 === 'Hello' || val1 === 'Goodbye') { + return true + } + return false } // This function should return a string that describes the provided age value. The @@ -33,6 +38,18 @@ function isHelloOrGoodbye(val1) { function getAgeDescription(age) { // TODO: write code in this function body to pass the tests + let input = age + if (input === 0) { + return 'Baby' + } else if (input >= 1 && input <= 4) { + return 'Toddler' + } else if (input >= 5 && input <= 12) { + return 'Child' + } else if (input >= 13 && input <= 19) { + return 'Teenager' + } else if (input >= 20) { + return 'Adult' + } } module.exports = { From 30594894a4abd19d9cdb8a993d7159146feaafaa Mon Sep 17 00:00:00 2001 From: Elvis Onobhayedo Date: Sat, 18 Dec 2021 13:44:09 +0000 Subject: [PATCH 12/12] more current --- 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 35717225..084bd48c 100644 --- a/src/demo/demo.js +++ b/src/demo/demo.js @@ -9,8 +9,8 @@ numThree = 5 // TODO: Update the code below so that the tests pass -const numOnePlusNumTwo = numOne + NumTwo - // 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 = {