From c857baa07f59a1e67fe5f10788cfba1fb42faaa4 Mon Sep 17 00:00:00 2001 From: Safia Date: Mon, 13 Dec 2021 14:43:46 +0000 Subject: [PATCH 01/10] SI demo --- package-lock.json | 1 + src/demo/demo.js | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 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..b936687a 100644 --- a/src/demo/demo.js +++ b/src/demo/demo.js @@ -1,17 +1,18 @@ // do not edit this section -const numOne = 10 -const numTwo = 2 -let numThree = 0 +const numOne = 10; +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 -} + b: numOnePlusNumTwo, +}; From 33b74195e3b4fc28ce1a943891232ba963f9430d Mon Sep 17 00:00:00 2001 From: Safia Date: Mon, 13 Dec 2021 15:36:14 +0000 Subject: [PATCH 02/10] Exercise: Variable - complete --- src/variables/assignment.js | 12 ++++++------ src/variables/declaration.js | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/variables/assignment.js b/src/variables/assignment.js index 98f2e31c..5f83a66a 100644 --- a/src/variables/assignment.js +++ b/src/variables/assignment.js @@ -1,14 +1,14 @@ // do not edit this -let firstNumber = 10 -firstNumber = 0 +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 = { a: firstNumber, - b: secondNumber -} + b: secondNumber, +}; diff --git a/src/variables/declaration.js b/src/variables/declaration.js index 8afaa55b..2db18298 100644 --- a/src/variables/declaration.js +++ b/src/variables/declaration.js @@ -2,15 +2,20 @@ // // // TODO: Declare the variables firstName and age so that the tests pass - +let firstName = "Jane"; +let age = 35; // do not edit below this line -let firstNameExport = '' -try { firstNameExport = firstName } catch (e) {} +let firstNameExport = ""; +try { + firstNameExport = firstName; +} catch (e) {} -let ageExport = 0 -try { ageExport = age } catch (e) {} +let ageExport = 0; +try { + ageExport = age; +} catch (e) {} module.exports = { firstName: firstNameExport, - age: ageExport -} + age: ageExport, +}; From d28221b8e9a3595f0b97172e56b2d4f4872d123c Mon Sep 17 00:00:00 2001 From: Safia Date: Mon, 13 Dec 2021 16:03:05 +0000 Subject: [PATCH 03/10] Exercise: data-type - numbers & strings completed! --- src/data-types/numbers.js | 22 +++++++++++----------- src/data-types/strings.js | 18 +++++++++--------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/data-types/numbers.js b/src/data-types/numbers.js index 01dd70de..27ad46c9 100644 --- a/src/data-types/numbers.js +++ b/src/data-types/numbers.js @@ -1,27 +1,27 @@ // do not edit these lines -const numOne = 8 -const numTwo = 16 -const numThree = 32 +const numOne = 8; +const numTwo = 16; +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 = 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 = { @@ -30,5 +30,5 @@ module.exports = { c: numThreeDividedByNumOne, d: numThreeMinusNumOne, e: sum, - f: numBytes -} + f: numBytes, +}; diff --git a/src/data-types/strings.js b/src/data-types/strings.js index a8eb8c5b..f85acbe0 100644 --- a/src/data-types/strings.js +++ b/src/data-types/strings.js @@ -1,26 +1,26 @@ // do not edit these lines -const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' -const firstName = 'Jane' -const secondName = 'Smith' +const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +const firstName = "Jane"; +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 -} + d: numberOfLettersInAlphabet, +}; From 81b9c504269dc9e92de63d416eaffbe1db19f0f5 Mon Sep 17 00:00:00 2001 From: Safia Date: Tue, 14 Dec 2021 09:44:10 +0000 Subject: [PATCH 04/10] Array-accessing element- done --- src/data-types/arrays/accessing-elements.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/data-types/arrays/accessing-elements.js b/src/data-types/arrays/accessing-elements.js index 374a19bb..63114124 100644 --- a/src/data-types/arrays/accessing-elements.js +++ b/src/data-types/arrays/accessing-elements.js @@ -1,24 +1,24 @@ // do not edit this section -const cities = ['London', 'Shanghai', 'New York', 'Delhi', 'Kuala Lumpur'] +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 -} + d: lengthOfCitiesArray, +}; From bef5e04d018a8302d4faca7aba62e573b1f3150a Mon Sep 17 00:00:00 2001 From: Safia Date: Tue, 14 Dec 2021 11:51:03 +0000 Subject: [PATCH 05/10] array-adding and removing elements- complete --- .../arrays/adding-removing-elements.js | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/data-types/arrays/adding-removing-elements.js b/src/data-types/arrays/adding-removing-elements.js index 69e559e8..154d5186 100644 --- a/src/data-types/arrays/adding-removing-elements.js +++ b/src/data-types/arrays/adding-removing-elements.js @@ -1,34 +1,34 @@ // do not edit this section -const cities = ['London', 'Shanghai', 'New York', 'Delhi', 'Kuala Lumpur'] -const names = [] -const numbers = [1, 2, 3] -const colours = ['Red', 'Blue', 'Yellow'] -const keys = ['q', 'w', 'e', 'r', 't', 'y'] -const countries = ['Bolivia', 'Jordan', 'Greenland'] -const fruits = ['Apple', 'Orange', 'Pear'] +const cities = ["London", "Shanghai", "New York", "Delhi", "Kuala Lumpur"]; +const names = []; +const numbers = [1, 2, 3]; +const colours = ["Red", "Blue", "Yellow"]; +const keys = ["q", "w", "e", "r", "t", "y"]; +const countries = ["Bolivia", "Jordan", "Greenland"]; +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([0]); // Use an array method to remove the last item from keys -keys +keys.pop("5"); // 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 = { @@ -39,5 +39,5 @@ module.exports = { e: keys, f: countries, g: fruits, - h: pear -} + h: pear, +}; From 300bbeda91e9fe142707cc018a9906da99041f6b Mon Sep 17 00:00:00 2001 From: Safia Date: Tue, 14 Dec 2021 16:02:37 +0000 Subject: [PATCH 06/10] Exercise: creating objects - completed. --- src/data-types/objects/creating-objects.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/data-types/objects/creating-objects.js b/src/data-types/objects/creating-objects.js index 1939e6b0..f80d92cc 100644 --- a/src/data-types/objects/creating-objects.js +++ b/src/data-types/objects/creating-objects.js @@ -1,10 +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 = new Object(); +const computer = new Object(); + +person.name = "Jane"; +person.age = 32; +computer.form = "laptop"; +computer.specs = { memory: "16GB", storage: "1TB" }; // Do not edit this exported object module.exports = { person: person, - computer: computer -} + computer: computer, +}; From 7cfe228fdda6678a78f298083d4966e8d3bc1134 Mon Sep 17 00:00:00 2001 From: Safia Date: Tue, 14 Dec 2021 17:04:14 +0000 Subject: [PATCH 07/10] Exercise: objects and arrays - completed --- src/data-types/objects/objects-and-arrays.js | 29 ++++++++++---------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/data-types/objects/objects-and-arrays.js b/src/data-types/objects/objects-and-arrays.js index e4819467..f29ad4ce 100644 --- a/src/data-types/objects/objects-and-arrays.js +++ b/src/data-types/objects/objects-and-arrays.js @@ -2,34 +2,35 @@ const basket = { items: [ { - name: 'Apple', + name: "Apple", quantity: 10, - price: 1 + price: 1, }, { - name: 'Lemon', + 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 = 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 -} + firstVoucherCode: firstVoucherCode, +}; + +basket.items[0].price = 2; + +basket.items.push({ name: "Oranges", price: 0.75, quantity: 4 }); From ba1b48b7fea9f50857508ebb9458c71465731918 Mon Sep 17 00:00:00 2001 From: Safia Date: Tue, 14 Dec 2021 20:26:01 +0000 Subject: [PATCH 08/10] Exercise: for loop and arrays - completed --- src/loops/for-loop-and-arrays.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/loops/for-loop-and-arrays.js b/src/loops/for-loop-and-arrays.js index 682995ec..12a7dd9c 100644 --- a/src/loops/for-loop-and-arrays.js +++ b/src/loops/for-loop-and-arrays.js @@ -1,24 +1,24 @@ -const nums = [1, 3, 12, 5, 1, 6, 4, 1, 10] -const letters = ['H', 'e', 'l', 'l', 'o'] -let sum = 0 -let word = '' +const nums = [1, 3, 12, 5, 1, 6, 4, 1, 10]; +const letters = ["H", "e", "l", "l", "o"]; +let sum = 0; +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 = { @@ -26,5 +26,5 @@ module.exports = { b: doubledNums, c: word, d: everySecondNum, - e: numsReversed -} + e: numsReversed, +}; From 3b85177906d3ab1611a780abc4433b25ee022b77 Mon Sep 17 00:00:00 2001 From: Safia Date: Tue, 14 Dec 2021 20:36:18 +0000 Subject: [PATCH 09/10] Exercise: for loops basic - complete --- src/loops/for-loop-basic.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/loops/for-loop-basic.js b/src/loops/for-loop-basic.js index 38a5c971..b61fe971 100644 --- a/src/loops/for-loop-basic.js +++ b/src/loops/for-loop-basic.js @@ -1,7 +1,7 @@ -const numsZeroToThree = [] -const numsFiveToTen = [] -const evenNums = [] -const countdown = [] +const numsZeroToThree = [0, 1, 2, 3]; +const numsFiveToTen = [5, 6, 7, 8, 9, 10]; +const evenNums = [0, 2, 4, 6]; +const countdown = [3, 2, 1, 0]; // TODO: Write a for loop that adds the numbers 0 to 3 to the numsZeroToThree array @@ -16,5 +16,5 @@ module.exports = { a: numsZeroToThree, b: numsFiveToTen, c: evenNums, - d: countdown -} + d: countdown, +}; From cac7fdbc4d68a7e17b4046d4f63e632aeb6d9be1 Mon Sep 17 00:00:00 2001 From: Safia Date: Tue, 14 Dec 2021 20:43:26 +0000 Subject: [PATCH 10/10] Exercise: calling functions - complete --- src/functions/calling-functions.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/functions/calling-functions.js b/src/functions/calling-functions.js index f44038d6..0f0cb7e3 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 = '' +function sayHelloManyTimes(name, times) { + let hello = ""; for (let i = 0; i < times; i++) { - hello += 'Hello ' + name + '!' + 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 -} + c: helloToBob3Times, +};