From f3fbfbf214a5e1c7279ad1b6852092751893fe08 Mon Sep 17 00:00:00 2001 From: MikeCiccia Date: Mon, 7 Mar 2022 18:38:33 +0100 Subject: [PATCH 1/3] 1commit --- boolean-conditions.js | 0 package-lock.json | 1 + src/conditional-flow/boolean-conditions.js | 2 +- src/data-types/arrays/accessing-elements.js | 8 ++++---- src/data-types/arrays/adding-removing-elements.js | 15 ++++++++------- src/data-types/numbers.js | 14 ++++++-------- src/data-types/objects/creating-objects.js | 12 ++++++++++-- src/data-types/strings.js | 10 +++++----- src/loops/example.js | 3 ++- src/variables/declaration.js | 2 +- 10 files changed, 38 insertions(+), 29 deletions(-) create mode 100644 boolean-conditions.js diff --git a/boolean-conditions.js b/boolean-conditions.js new file mode 100644 index 00000000..e69de29b 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/conditional-flow/boolean-conditions.js b/src/conditional-flow/boolean-conditions.js index 70b623d4..e41ae70d 100644 --- a/src/conditional-flow/boolean-conditions.js +++ b/src/conditional-flow/boolean-conditions.js @@ -2,7 +2,7 @@ // "Well done, you passed!" if the value is true, or "Sorry, try again" // if the value is false. function getResult (didPass) { - +console.log("interaction",) // TODO: write code in this function body to pass the tests } diff --git a/src/data-types/arrays/accessing-elements.js b/src/data-types/arrays/accessing-elements.js index 374a19bb..4dbc3403 100644 --- a/src/data-types/arrays/accessing-elements.js +++ b/src/data-types/arrays/accessing-elements.js @@ -4,16 +4,16 @@ const cities = ['London', 'Shanghai', 'New York', 'Delhi', 'Kuala Lumpur'] // TODO: write code to pass the tests // Set names equal to an array containing 'Bob', 'Jane', 'Joanna' in that order -const names = null +const names = ['Bob', 'Jane', 'Joanna'] // Set fourthCity to the 4th element in the cities array -const fourthCity = '' +const fourthCity = 'Delhi' // Set firstCity to the 1st element in the cities array -const firstCity = '' +const firstCity = 'London' // Set lengthOfCitiesArray to the length of the cities array -const lengthOfCitiesArray = NaN +const lengthOfCitiesArray = cities.length // Do not edit this exported object module.exports = { diff --git a/src/data-types/arrays/adding-removing-elements.js b/src/data-types/arrays/adding-removing-elements.js index 69e559e8..15f428d0 100644 --- a/src/data-types/arrays/adding-removing-elements.js +++ b/src/data-types/arrays/adding-removing-elements.js @@ -10,26 +10,27 @@ 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() +fruits.splice(2, 1) // Do not edit this exported object module.exports = { a: names, diff --git a/src/data-types/numbers.js b/src/data-types/numbers.js index 01dd70de..efd57ea6 100644 --- a/src/data-types/numbers.js +++ b/src/data-types/numbers.js @@ -6,22 +6,20 @@ 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..1eb298bf 100644 --- a/src/data-types/objects/creating-objects.js +++ b/src/data-types/objects/creating-objects.js @@ -1,7 +1,15 @@ // 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: 'mike', + age: 75 +} +const computer = { + form: 'laptop', + specs: { + memory: '1gB', + } +} // Do not edit this exported object module.exports = { diff --git a/src/data-types/strings.js b/src/data-types/strings.js index a8eb8c5b..73e449c5 100644 --- a/src/data-types/strings.js +++ b/src/data-types/strings.js @@ -6,17 +6,17 @@ const secondName = 'Smith' // TODO: Update the code using Javascript string operations and the variables above so that the tests pass. // Set this variable to firstName and secondName concatenated -const fullName = null +const fullName = "Jane" + " " + "Smith" // Set this variable to the 10th character of the alphabet variable -const tenthCharacterOfAlphabet = null +const tenthCharacterOfAlphabet = alphabet[9] // Set this variable by calling a method on the alphabet variable to transform it to lower case -const lowerCaseAlphabet = null -// Set this variable by using a property on the alphabet variable to get it's length -const numberOfLettersInAlphabet = null +const lowerCaseAlphabet = alphabet.toLowerCase() +// Set this variable by using a property on the alphabet variable to get it's length +const numberOfLettersInAlphabet = alphabet.length // do not edit the exported object. module.exports = { a: fullName, diff --git a/src/loops/example.js b/src/loops/example.js index eee24f17..d9c69772 100644 --- a/src/loops/example.js +++ b/src/loops/example.js @@ -7,7 +7,8 @@ const nums3 = [] for (let i = 1; i < 6; i++) { nums.push(i) } - +console.log("i<5") +e // TODO: Write a for loop to add the all but the last number of nums to the nums2 array for (let i = 0; i < nums2.length - 1; i++) { nums3.push(nums2[i]) diff --git a/src/variables/declaration.js b/src/variables/declaration.js index 8afaa55b..42e1e17b 100644 --- a/src/variables/declaration.js +++ b/src/variables/declaration.js @@ -4,7 +4,7 @@ // TODO: Declare the variables firstName and age so that the tests pass // do not edit below this line -let firstNameExport = '' +let firstNameExport = '1' try { firstNameExport = firstName } catch (e) {} let ageExport = 0 From 01cc50237949efd9899a1664bbaaa6160acbe150 Mon Sep 17 00:00:00 2001 From: MikeCiccia Date: Tue, 8 Mar 2022 16:33:32 +0100 Subject: [PATCH 2/3] final commit --- src/functions/calling-functions.js | 6 +++--- src/loops/for-loop-and-arrays.js | 15 +++++++++++---- src/loops/for-loop-basic.js | 12 ++++++++---- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/functions/calling-functions.js b/src/functions/calling-functions.js index f44038d6..5e86dd2c 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/loops/for-loop-and-arrays.js b/src/loops/for-loop-and-arrays.js index 682995ec..37f8f976 100644 --- a/src/loops/for-loop-and-arrays.js +++ b/src/loops/for-loop-and-arrays.js @@ -7,19 +7,26 @@ let word = '' // Use a for loop to set the sum variable to the sum of all the values in nums sum = 0 - +for (let i = 0; i < nums.length; i++){ + sum = sum + nums[i]; + } // Use a for loop to populate doubledNums with every value from nums array doubled (i.e [2, 6, 24, etc...]) const doubledNums = [] - +for (let i = 0; i < nums.length; i++){ + doubledNums.push(nums[i]*2) // Use a for loop to set word equal to all the letters in the letters array word = '' +for(let i = 0; i < letters.length; i++){ + word = word + letters[i]; // Use a for loop to populate everySecondNum with every second number from the nums array const everySecondNum = [] - +for (let i = 1; i < nums.length; i+=2){ + everySecondNum.push(nums[i]) // Use a for loop to populate numsReversed with the numbers from nums in reverse order const numsReversed = [] - + for (i = nums.length -1; i >= 0; i--){ + numsReversed.push(nums[i]); // do not change below this line module.exports = { a: sum, diff --git a/src/loops/for-loop-basic.js b/src/loops/for-loop-basic.js index 38a5c971..327abca8 100644 --- a/src/loops/for-loop-basic.js +++ b/src/loops/for-loop-basic.js @@ -4,13 +4,17 @@ 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 <= 3; 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 <= 10; i++){ + numsFiveToTen.push(i // TODO: Write a for loop that adds all the even numbers between 0 and 6 (0, 2, 4, 6) to evenNums - +for (let i = 0; i <= 6; i++){ + if(i % 2 === 0) evenNums.push(i) // TODO: Write a for loop that adds the numbers 3 to 0 (in that order) to the countdown array - +for (let i = 3 ; i >= 0 ; i--){ + countdown.push(i) // do not change below this line module.exports = { a: numsZeroToThree, From 2d4af8f5898298ecc0e6100f3dd43f09ecfa47d2 Mon Sep 17 00:00:00 2001 From: MikeCiccia Date: Wed, 9 Mar 2022 18:30:01 +0100 Subject: [PATCH 3/3] final commit --- src/data-types/arrays/accessing-elements.js | 4 ++-- src/data-types/arrays/adding-removing-elements.js | 4 ++-- src/functions/creating-functions.js | 12 ++++++++---- src/variables/assignment.js | 4 ++-- src/variables/declaration.js | 3 ++- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/data-types/arrays/accessing-elements.js b/src/data-types/arrays/accessing-elements.js index 4dbc3403..8a46a2fd 100644 --- a/src/data-types/arrays/accessing-elements.js +++ b/src/data-types/arrays/accessing-elements.js @@ -7,10 +7,10 @@ const cities = ['London', 'Shanghai', 'New York', 'Delhi', 'Kuala Lumpur'] const names = ['Bob', 'Jane', 'Joanna'] // Set fourthCity to the 4th element in the cities array -const fourthCity = 'Delhi' +const fourthCity = cities(3) // Set firstCity to the 1st element in the cities array -const firstCity = 'London' +const firstCity = cities(0) // Set lengthOfCitiesArray to the length of the cities array const lengthOfCitiesArray = cities.length diff --git a/src/data-types/arrays/adding-removing-elements.js b/src/data-types/arrays/adding-removing-elements.js index 15f428d0..e3c957f6 100644 --- a/src/data-types/arrays/adding-removing-elements.js +++ b/src/data-types/arrays/adding-removing-elements.js @@ -19,10 +19,10 @@ numbers.push(4) cities.unshift("rio") // Use an array method to remove the first item from colours -colours.shift +colours.shift() // Use an array method to remove the last item from keys -keys.pop +keys.pop() // Use an array method to remove 'Jordon' from the countries array countries.splice(1,1) diff --git a/src/functions/creating-functions.js b/src/functions/creating-functions.js index 2d2ac5e6..355fbd07 100644 --- a/src/functions/creating-functions.js +++ b/src/functions/creating-functions.js @@ -7,7 +7,8 @@ // 2 | 3 // // TODO: write code below - +function incrementsNumber(num){ + return num + 1 // Define a function that takes any person's name and returns it with a smiley :)! // Remember to make the name capitalized! // @@ -18,9 +19,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: incrementsNumber, // change undefined to be the name of the function you defined to increment a number (the first TODO) + b: Smiley // change undefined to be the name of the function you defined to say hi (the second TODO) diff --git a/src/variables/assignment.js b/src/variables/assignment.js index 98f2e31c..e2c79f0c 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 42e1e17b..38607608 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 = '1' try { firstNameExport = firstName } catch (e) {}