Skip to content

Davina scott assignment #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added davina-scott-assignment/.DS_Store
Binary file not shown.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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;


}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

}
},
{
Expand All @@ -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

}
},
{
Expand All @@ -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
}
},
]
Expand All @@ -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");
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.