From 2da3717d7131d06be88425172dda5b8f293058d6 Mon Sep 17 00:00:00 2001 From: davinascott Date: Fri, 28 Oct 2022 23:21:24 -0500 Subject: [PATCH 1/2] Assignment is 90 percent complete --- .../.gitignore | 0 .../01/README.md | 0 .../01/exercise.test.js | 9 +++++ .../02/README.md | 0 .../02/exercise.test.js | 8 +++++ .../03/README.md | 0 .../03/exercise.test.js | 13 +++++++ .../04/README.md | 0 .../04/exercise.test.js | 7 ++++ .../05/README.md | 0 .../05/exercise.test.js | 6 +++- .../06/README.md | 0 .../06/exercise.test.js | 35 +++++++++++++++++++ .../07/README.md | 0 .../07/exercise.test.js | 4 +++ .../08/README.md | 0 .../08/exercise.test.js | 28 +++++++++++++++ .../package-lock.json | 0 .../package.json | 3 +- .../vitest.config.js | 0 package-lock.json | 6 ++++ 21 files changed, 117 insertions(+), 2 deletions(-) rename {assignment => davina-scott-assignment}/.gitignore (100%) rename {assignment => davina-scott-assignment}/01/README.md (100%) rename {assignment => davina-scott-assignment}/01/exercise.test.js (67%) rename {assignment => davina-scott-assignment}/02/README.md (100%) rename {assignment => davina-scott-assignment}/02/exercise.test.js (70%) rename {assignment => davina-scott-assignment}/03/README.md (100%) rename {assignment => davina-scott-assignment}/03/exercise.test.js (56%) rename {assignment => davina-scott-assignment}/04/README.md (100%) rename {assignment => davina-scott-assignment}/04/exercise.test.js (70%) rename {assignment => davina-scott-assignment}/05/README.md (100%) rename {assignment => davina-scott-assignment}/05/exercise.test.js (75%) rename {assignment => davina-scott-assignment}/06/README.md (100%) rename {assignment => davina-scott-assignment}/06/exercise.test.js (52%) rename {assignment => davina-scott-assignment}/07/README.md (100%) rename {assignment => davina-scott-assignment}/07/exercise.test.js (89%) rename {assignment => davina-scott-assignment}/08/README.md (100%) rename {assignment => davina-scott-assignment}/08/exercise.test.js (66%) rename {assignment => davina-scott-assignment}/package-lock.json (100%) rename {assignment => davina-scott-assignment}/package.json (78%) rename {assignment => davina-scott-assignment}/vitest.config.js (100%) create mode 100644 package-lock.json diff --git a/assignment/.gitignore b/davina-scott-assignment/.gitignore similarity index 100% rename from assignment/.gitignore rename to davina-scott-assignment/.gitignore diff --git a/assignment/01/README.md b/davina-scott-assignment/01/README.md similarity index 100% rename from assignment/01/README.md rename to davina-scott-assignment/01/README.md diff --git a/assignment/01/exercise.test.js b/davina-scott-assignment/01/exercise.test.js similarity index 67% rename from assignment/01/exercise.test.js rename to davina-scott-assignment/01/exercise.test.js index f72dfa5..6783c7b 100644 --- a/assignment/01/exercise.test.js +++ b/davina-scott-assignment/01/exercise.test.js @@ -6,6 +6,15 @@ describe('Exercise 01', () => { function multipleOf5Or9(positiveNumber) { // Your code here + const x = positiveNumber/5 + const y = positiveNumber/9 + if (Number.isInteger(x) ){ + return true; + } else if (Number.isInteger(y)){ + return true; + } else { + return false; + } } diff --git a/assignment/02/README.md b/davina-scott-assignment/02/README.md similarity index 100% rename from assignment/02/README.md rename to davina-scott-assignment/02/README.md diff --git a/assignment/02/exercise.test.js b/davina-scott-assignment/02/exercise.test.js similarity index 70% rename from assignment/02/exercise.test.js rename to davina-scott-assignment/02/exercise.test.js index f0e30e0..6838bd9 100644 --- a/assignment/02/exercise.test.js +++ b/davina-scott-assignment/02/exercise.test.js @@ -8,6 +8,14 @@ describe('02', () => { function lastThree(str) { // Your code here + if (str.length >= 3){ + const lastThreeChar = str.slice(-3) + const newString = lastThreeChar + str + lastThreeChar + return newString + + } else { + return false; + } } diff --git a/assignment/03/README.md b/davina-scott-assignment/03/README.md similarity index 100% rename from assignment/03/README.md rename to davina-scott-assignment/03/README.md diff --git a/assignment/03/exercise.test.js b/davina-scott-assignment/03/exercise.test.js similarity index 56% rename from assignment/03/exercise.test.js rename to davina-scott-assignment/03/exercise.test.js index ff038c8..c9f90ee 100644 --- a/assignment/03/exercise.test.js +++ b/davina-scott-assignment/03/exercise.test.js @@ -3,6 +3,19 @@ describe('03', () => { function isSix(x, y) { // Your code here + const sum = x + y + const xDifference = x - y + const yDifference = y - x + + if ((x == 6) || (y == 6)){ + return true; + } else if ((xDifference == 6) || (yDifference == 6)){ + return true; + } else if (sum == 6){ + return true; + } else { + return false; + } } diff --git a/assignment/04/README.md b/davina-scott-assignment/04/README.md similarity index 100% rename from assignment/04/README.md rename to davina-scott-assignment/04/README.md diff --git a/assignment/04/exercise.test.js b/davina-scott-assignment/04/exercise.test.js similarity index 70% rename from assignment/04/exercise.test.js rename to davina-scott-assignment/04/exercise.test.js index 7fb23e5..b565f00 100644 --- a/assignment/04/exercise.test.js +++ b/davina-scott-assignment/04/exercise.test.js @@ -3,6 +3,13 @@ describe('04', () => { const arrayIncludes5Or2 = (array) => { // Your code here + for (let i = 0; i < array.length; i++){ + const arrayElement = array[i] + if ((arrayElement == 5) || (arrayElement === 2)){ + return true; + } + } return false; + } diff --git a/assignment/05/README.md b/davina-scott-assignment/05/README.md similarity index 100% rename from assignment/05/README.md rename to davina-scott-assignment/05/README.md diff --git a/assignment/05/exercise.test.js b/davina-scott-assignment/05/exercise.test.js similarity index 75% rename from assignment/05/exercise.test.js rename to davina-scott-assignment/05/exercise.test.js index b00a829..ec84bf5 100644 --- a/assignment/05/exercise.test.js +++ b/davina-scott-assignment/05/exercise.test.js @@ -4,7 +4,11 @@ describe('05', () => { const sum = (array) => { // Your code here - + var sum = 0; + for (let i = 0; i < array.length; i++){ + sum = sum + array[i]; + } + return sum; } // Test cases diff --git a/assignment/06/README.md b/davina-scott-assignment/06/README.md similarity index 100% rename from assignment/06/README.md rename to davina-scott-assignment/06/README.md diff --git a/assignment/06/exercise.test.js b/davina-scott-assignment/06/exercise.test.js similarity index 52% rename from assignment/06/exercise.test.js rename to davina-scott-assignment/06/exercise.test.js index 7ef6b30..86c8ade 100644 --- a/assignment/06/exercise.test.js +++ b/davina-scott-assignment/06/exercise.test.js @@ -9,6 +9,14 @@ describe('06', () => { markPaper: () => { // add a promise here that resolves after 2 seconds // and print "Maths paper marked" + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve('Maths paper marked'); + reject('Paper was not marked'); + }, 2000); + // return myPromise + }); + } }, { @@ -17,6 +25,14 @@ describe('06', () => { markPaper: () => { // add a promise here that resolves after 2 seconds // and print "Geology paper marked" + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve('Geology paper marked'); + reject('Paper was not marked'); + }, 2000); + }); + // return myPromise + } }, { @@ -25,6 +41,14 @@ describe('06', () => { markPaper: () => { // add a promise here that resolves after 2 seconds // and print "Social Studies paper marked" + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve('Social Studies paper marked'); + reject('Paper was not marked'); + }, 2000); + + }); + // return myPromise } }, ] @@ -33,6 +57,17 @@ describe('06', () => { const spyOnLog = vi.spyOn(console, 'log'); // Your code here + listOfPapers.forEach(element => { + const arrayResult = element.markPaper() + console.log(arrayResult) + if (element.wasSubmitted = true){ + arrayResult.then((value) => { + console.log(value); + }).catch((error) => { + expect(error).toBe('Promise rejected'); + }) + } + }); expect(spyOnLog).toHaveBeenCalledWith("Maths paper marked"); diff --git a/assignment/07/README.md b/davina-scott-assignment/07/README.md similarity index 100% rename from assignment/07/README.md rename to davina-scott-assignment/07/README.md diff --git a/assignment/07/exercise.test.js b/davina-scott-assignment/07/exercise.test.js similarity index 89% rename from assignment/07/exercise.test.js rename to davina-scott-assignment/07/exercise.test.js index 9517e93..3a2bb54 100644 --- a/assignment/07/exercise.test.js +++ b/davina-scott-assignment/07/exercise.test.js @@ -12,6 +12,10 @@ describe('07', () => { const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; // Your code here + array.forEach(element => { + const outputString = 'The current element is' + ' ' + element + console.log(outputString); + }); // Test cases expect(spyOnLog).toHaveBeenCalledWith('The current element is 1'); diff --git a/assignment/08/README.md b/davina-scott-assignment/08/README.md similarity index 100% rename from assignment/08/README.md rename to davina-scott-assignment/08/README.md diff --git a/assignment/08/exercise.test.js b/davina-scott-assignment/08/exercise.test.js similarity index 66% rename from assignment/08/exercise.test.js rename to davina-scott-assignment/08/exercise.test.js index 27f006c..6c5f9f6 100644 --- a/assignment/08/exercise.test.js +++ b/davina-scott-assignment/08/exercise.test.js @@ -16,7 +16,35 @@ describe('08', () => { test('Create a Vehicle class, and create different type of vehicles that extends', () => { // Your code here + class Car { + constructor(color, wheels, bodyType) { + this.wheels = wheels; + this.bodyType = bodyType; + this.color = color; + } + whatIsMyName() { + return this.carBodyType(); + } + + carBodyType() { + const stringBodyType = 'I am a' + ' ' + this.bodyType + return stringBodyType; + } + } + + class Truck extends Car{ + constructor(color, wheels, bodyType){ + super(color,wheels,bodyType); + + } + } + + class Motorcycle extends Car{ + constructor(color, wheels, bodyType){ + super(color,wheels,bodyType); + } + } // Expected outcome for the child classes const car = new Car('red', 4, 'sedan'); diff --git a/assignment/package-lock.json b/davina-scott-assignment/package-lock.json similarity index 100% rename from assignment/package-lock.json rename to davina-scott-assignment/package-lock.json diff --git a/assignment/package.json b/davina-scott-assignment/package.json similarity index 78% rename from assignment/package.json rename to davina-scott-assignment/package.json index a024e2c..e3b44a2 100644 --- a/assignment/package.json +++ b/davina-scott-assignment/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "test": "vitest run", - "exercise": "node ../setup/scripts.js" + "exercise": "node ../setup/scripts.js", + "ex": "npm run exercise --" }, "author": "Dimitri Harding", "license": "ISC", diff --git a/assignment/vitest.config.js b/davina-scott-assignment/vitest.config.js similarity index 100% rename from assignment/vitest.config.js rename to davina-scott-assignment/vitest.config.js diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..66f672f --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "javascript-and-git-automation-bootcamp", + "lockfileVersion": 2, + "requires": true, + "packages": {} +} From d4413cee8afb14a68df8293c31df30bbe8c30125 Mon Sep 17 00:00:00 2001 From: davinascott Date: Fri, 28 Oct 2022 23:45:14 -0500 Subject: [PATCH 2/2] All exercises completed except number 6 --- davina-scott-assignment/.DS_Store | Bin 0 -> 6148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 davina-scott-assignment/.DS_Store diff --git a/davina-scott-assignment/.DS_Store b/davina-scott-assignment/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..be214b034c61cc8d47ecbd901784665be114356d GIT binary patch literal 6148 zcmeH~u?oUK42F~HAh>jNyv1D?=cDKo^aUIQ7f}#&zDM^@E{mtL6!`fR2fxGo1vWo;LY;X~ujYEukMYrAMd0@LhZpaN8&QD9c{-p>C6{M-EBv@oRtRN&7P z(D{Dc4|u6KTR&dU>c^lP$m;ES0Fh_#@ylFi?S?D)0h& Cf)CCB literal 0 HcmV?d00001