Skip to content

my assignment #37

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
9 changes: 9 additions & 0 deletions Ru-ghey-Gilzeane/01/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Assignment Ex 01

In this exercise, you can expected to check if a positive number is a multiple 5 or a multiple of 9


Here is a visual of what is expected:

![Ex 01](https://github.com/QualityWorksCG/javascript-and-git-automation-bootcamp/main/media/ex-01.png)

25 changes: 25 additions & 0 deletions Ru-ghey-Gilzeane/01/exercise.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
describe('Exercise 01', () => {
test('01. Check if a positive number is a multiple of 5 or 9', () => {
/**
* You are expected to return a boolean value
*/

function multipleOf5Or9(positiveNumber) {
// Your code here
if (positiveNumber % 5 == 0 || positiveNumber % 9 == 0) {
return true;
}
else {
return false;
}
}

// Test cases
expect(multipleOf5Or9(10)).toBe(true);
expect(multipleOf5Or9(20)).toBe(true);
expect(multipleOf5Or9(21)).toBe(false);
expect(multipleOf5Or9(36)).toBe(true);
expect(multipleOf5Or9(22)).toBe(false);
expect(multipleOf5Or9(23)).toBe(false);
});
});
9 changes: 9 additions & 0 deletions Ru-ghey-Gilzeane/02/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Assignment Ex 02

Create a new string by taking the last 3 letters of an existing string and adding those letters at the back and the front of the new string.

Bear in mind that the existing string should be more than 3 characters

Here is a visual of what is expected:

![Ex 02](https://github.com/QualityWorksCG/javascript-and-git-automation-bootcamp/main/media/ex-02.png)
26 changes: 26 additions & 0 deletions Ru-ghey-Gilzeane/02/exercise.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
describe('02', () => {
it('02. Create a new string from any string by taking the last 3 letters of that string and adding it to the front and back.', () => {
/**
* If the length of the string is less than 3, return false.
*
* Remember we discussed splice() method in the previous exercise.
*/

function lastThree(str) {
// Your code here
if (str.length >= 3) {
const last = str.slice(-3);
return last + str + last;
}
else {
return false;
}

}

// Test cases
expect(lastThree('hello')).toBe('llohellollo');
expect(lastThree('wor')).toBe('worworwor');
expect(lastThree('qw')).toBe(false);
});
});
8 changes: 8 additions & 0 deletions Ru-ghey-Gilzeane/03/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Assignment Ex 03

Check between two integers which the difference is 6, the sum of them makes 6 or any of them is 6.


Here is a visual of what is expected:

![Ex 03](https://github.com/QualityWorksCG/javascript-and-git-automation-bootcamp/main/media/03-ex.png)
24 changes: 24 additions & 0 deletions Ru-ghey-Gilzeane/03/exercise.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
describe('03', () => {
it('03. Check if any of two number is 6, if the sum of them makes 6 or if the difference is 6', () => {

function isSix(x, y) {
// Your code here
if ((x == 6 && y == 6) || x + y == 6 || (y - x) == 6) {
return true;
}
else {
return false;
}

}

// Test cases
expect(isSix(6, 0)).toBe(true);
expect(isSix(0, 6)).toBe(true);
expect(isSix(3, 3)).toBe(true);
expect(isSix(3, 4)).toBe(false);
expect(isSix(3, 9)).toBe(true);
expect(isSix(3, 3)).toBe(true);
expect(isSix(3, 3)).toBe(true);
});
});
7 changes: 7 additions & 0 deletions Ru-ghey-Gilzeane/04/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Assignment Ex 04

Check if an array of 3 items, contains a 5 or 2

Here is a visual:

![Ex 04](https://github.com/QualityWorksCG/javascript-and-git-automation-bootcamp/main/media/04-ex.png)
24 changes: 24 additions & 0 deletions Ru-ghey-Gilzeane/04/exercise.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
describe('04', () => {
test('Check if an array of 3 items, contains a 5 or 2', () => {

const arrayIncludes5Or2 = (array) => {
// Your code here
for (let x = 0; x < array.length; x++) {
if (array[x] == 5 || array[x] == 2) {
return true;
}
}
return false;
}

// Test cases
expect(arrayIncludes5Or2([1, 2, 3])).toBe(true);
expect(arrayIncludes5Or2([1, 4, 3])).toBe(false);
expect(arrayIncludes5Or2([1, 4, 5])).toBe(true);
expect(arrayIncludes5Or2([1, 4, 6])).toBe(false);
expect(arrayIncludes5Or2([1, 4, 7])).toBe(false);
expect(arrayIncludes5Or2([1, 4, 8])).toBe(false);
expect(arrayIncludes5Or2([1, 4, 9])).toBe(false);

});
})
3 changes: 3 additions & 0 deletions Ru-ghey-Gilzeane/05/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Assignment Ex 05

Take an array of any length and add all elements to return a sum
23 changes: 23 additions & 0 deletions Ru-ghey-Gilzeane/05/exercise.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe('05', () => {
it('Take an array of any length and add all elements to return a sum', () => {


const sum = (array) => {
// Your code here
let sumofarray = 0;
for (let x of array)
sumofarray += x;
return sumofarray;
console.log(sum)

}

// Test cases
expect(sum([1, 2, 3])).toBe(6);
expect(sum([1, 4, 3, 50, 10])).toBe(68);
expect(sum([1, 4, 5, 6, 7, 8, 9, 10])).toBe(50);
expect(sum([1, 4, 6, 7, 8, 9, 10])).toBe(45);
expect(sum([1, 4, 7, 8, 9, 10])).toBe(39);
expect(sum([1, 4, 8, 9, 10])).toBe(32);
});
})
29 changes: 29 additions & 0 deletions Ru-ghey-Gilzeane/06/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
You just got a new Job as a teacher, and you have a bunch of exam paper to mark.

From the following list of papers check if each individual one is submitted, and if so send that paper for marking which is a async function.

```js
const listOfPapers = [
{
subject: "Math",
wasSubmitted: true,
markPaper: () => {

}
},
{
subject: "Geology",
wasSubmitted: true,
markPaper: () => {

}
},
{
subject: "Social Studies",
wasSubmitted: false,
markPaper: () => {

}
},
]
```
71 changes: 71 additions & 0 deletions Ru-ghey-Gilzeane/06/exercise.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
describe('06', () => {

// Tip: Use setTimeout to delay the execution of marking

const listOfPapers = [
{
subject: "Maths",
wasSubmitted: true,
markPaper: () => {
// add a promise here that resolves after 2 seconds
// and print "Maths paper marked"
const grade = new Promise((resolve) => {
setTimeout(() => {
resolve('Maths paper marked');
}, 2000);
});
return grade;

}
},
{
subject: "Geology",
wasSubmitted: true,
markPaper: () => {
// add a promise here that resolves after 2 seconds
// and print "Geology paper marked"
const grade = new Promise((resolve) => {
setTimeout(() => {
resolve('Geology paper marked');
}, 2000);
});
return grade;
}
},
{
subject: "Social Studies",
wasSubmitted: false,
markPaper: () => {
// add a promise here that resolves after 2 seconds
// and print "Social Studies paper marked"
const grade = new Promise((resolve) => {
setTimeout(() => {
resolve('Social Studies paper marked');
}, 2000);
});
return grade;
}
},
]

it('Check if a paper was submitted, and if yes, wait for it to be marked', async () => {
const spyOnLog = vi.spyOn(console, 'log');

// Your code here
for (let x of listOfPapers) {
if (x.wasSubmitted == true) {
const results = await x.markPaper();
console.log(results)
}
}



expect(spyOnLog).toHaveBeenCalledWith("Maths paper marked");
expect(spyOnLog).toHaveBeenCalledWith("Geology paper marked");
expect(spyOnLog).not.toHaveBeenCalledWith("Social Studies paper marked");
expect(listOfPapers[0].markPaper()).toBeInstanceOf(Promise);
expect(listOfPapers[1].markPaper()).toBeInstanceOf(Promise);
expect(listOfPapers[2].markPaper()).toBeInstanceOf(Promise);
});
});
5 changes: 5 additions & 0 deletions Ru-ghey-Gilzeane/07/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
An Array has lots of methods that you can use. In the bootcamp you learn about
iterating an array using for keyword, but you can iterate an array with an array method


Using the "forEach" array method, print the current element
31 changes: 31 additions & 0 deletions Ru-ghey-Gilzeane/07/exercise.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
describe('07', () => {
test('Using the "forEach" array method, print the current element', () => {
const spyOnLog = vi.spyOn(console, 'log');
/**
* You are expected to use the forEach array method
*
* You are expected to use the console.log() method
*
* You are expected to use the template literal syntax
* Example: `The current element is ....`
*/
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

// Your code here
array.forEach(function (x) {
console.log(`The current element is ${x}`);
});

// Test cases
expect(spyOnLog).toHaveBeenCalledWith('The current element is 1');
expect(spyOnLog).toHaveBeenCalledWith('The current element is 2');
expect(spyOnLog).toHaveBeenCalledWith('The current element is 3');
expect(spyOnLog).toHaveBeenCalledWith('The current element is 4');
expect(spyOnLog).toHaveBeenCalledWith('The current element is 5');
expect(spyOnLog).toHaveBeenCalledWith('The current element is 6');
expect(spyOnLog).toHaveBeenCalledWith('The current element is 7');
expect(spyOnLog).toHaveBeenCalledWith('The current element is 8');
expect(spyOnLog).toHaveBeenCalledWith('The current element is 9');
expect(spyOnLog).toHaveBeenCalledWith('The current element is 10');
});
});
13 changes: 13 additions & 0 deletions Ru-ghey-Gilzeane/08/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
When working with classes, you normally have common traits or properties in your Parent and children from that parent would have specific treats.

You are the manager of a new Vehicle company

And you need to create different kind of cars to list in your inventory.

1. Create a Vehicle parent
- wheels as a property
- bodyType as a property

2. Create different kind of vehicles from the parent
- each vehicle should have a color
- each vehicle should have a method called "whatIsMyName" that prints the vehicle name
Loading