Skip to content
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
15 changes: 15 additions & 0 deletions .test-summary/TEST_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Test Summary

**Mentors**: For more information on how to review homework assignments, please refer to the [Review Guide](https://github.com/HackYourFuture/mentors/blob/main/assignment-support/review-guide.md).

### 1-JavaScript - Week2

| Exercise | Passed | Failed | ESLint |
|----------------------|--------|--------|--------|
| ex1-giveCompliment | 7 | - | ✓ |
| ex2-dogYears | 7 | - | ✓ |
| ex3-tellFortune | 10 | - | ✓ |
| ex4-shoppingCart | - | - | ✓ |
| ex5-shoppingCartPure | - | - | ✓ |
| ex6-totalCost | - | - | ✓ |
| ex7-mindPrivacy | - | - | ✓ |
42 changes: 23 additions & 19 deletions 1-JavaScript/Week2/assignment/ex1-giveCompliment.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
/* -----------------------------------------------------------------------------
Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week3#exercise-1-you-are-amazing

1. Complete the function named `giveCompliment`as follows:

- It should take a single parameter: `name`.
- Its function body should include a variable that holds an array,
`compliments`, initialized with 10 strings. Each string should be a
compliment, like `"great"`, `"awesome"` and so on.
- It should randomly select a compliment from the array.
- It should return the string "You are `compliment`, `name`!", where
`compliment` is a randomly selected compliment and `name` is the name that
was passed as an argument to the function.

2. Call the function three times, giving each function call the same argument:
your name.
Use `console.log` each time to display the return value of the
`giveCompliment` function to the console.
This function gives a random compliment to the name passed as an argument.
-----------------------------------------------------------------------------*/
export function giveCompliment(/* TODO parameter(s) go here */) {
// TODO complete this function
export function giveCompliment(name) {
// Array of 10 compliments
const compliments = [
'awesome',
'fantastic',
'amazing',
'incredible',
'wonderful',
'brilliant',
'outstanding',
'excellent',
'marvelous',
'great',
];

// Pick a random compliment
const randomIndex = Math.floor(Math.random() * compliments.length);
const compliment = compliments[randomIndex];

// Return the final string
return `You are ${compliment}, ${name}!`;
}

function main() {
// TODO substitute your own name for "HackYourFuture"
const myName = 'HackYourFuture';
const myName = 'Majd';

console.log(giveCompliment(myName));
console.log(giveCompliment(myName));
Expand Down
23 changes: 8 additions & 15 deletions 1-JavaScript/Week2/assignment/ex2-dogYears.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
/*------------------------------------------------------------------------------
Full description at: https://github.com/HackYourFuture/Assignment/tree/main/1-JavaScript/Week3#exercise-2-dog-years

You know how old your dog is in human years, but what about dog years? Let's
calculate it!
This function calculates a dog's age in dog years based on the input human years.
------------------------------------------------------------------------------*/
export function calculateDogAge(humanYears) {
// Step 1: Multiply the human years by 7 to get dog years
const dogYears = humanYears * 7;

1. Complete the function named `calculateDogAge`.

- It takes one parameter: your (fictional) puppy's age (number).
- Calculate your dog's age based on the conversion rate of 1 human year to
7 dog years.
- Return a string: "Your doggie is `age` years old in dog years!"

2. Use `console.log` to display the result of the function for three different
ages.
-----------------------------------------------------------------------------*/

export function calculateDogAge(/* TODO parameter(s) go here */) {
// TODO complete this function
// Step 2: Return the final string
return `Your doggie is ${dogYears} years old in dog years!`;
}

function main() {
// Test the function with three different ages
console.log(calculateDogAge(1)); // -> "Your doggie is 7 years old in dog years!"
console.log(calculateDogAge(2)); // -> "Your doggie is 14 years old in dog years!"
console.log(calculateDogAge(3)); // -> "Your doggie is 21 years old in dog years!"
Expand Down
40 changes: 21 additions & 19 deletions 1-JavaScript/Week2/assignment/ex3-tellFortune.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,32 @@ body, this code is now written once only in a separated function.

// This function should take an array as its parameter and return
// a randomly selected element as its return value.
function selectRandomly(/* TODO parameter(s) go here */) {
// TODO complete this function
function selectRandomly(array) {
const randomIndex = Math.floor(Math.random() * array.length);
return array[randomIndex];
}

export function tellFortune(/* TODO add parameter(s) here */) {
// TODO complete this function
export function tellFortune(
numKidsArray,
partnerNamesArray,
locationsArray,
jobTitlesArray
) {
// Select random elements from each array using selectRandomly
const numKids = selectRandomly(numKidsArray);
const partnerName = selectRandomly(partnerNamesArray);
const location = selectRandomly(locationsArray);
const jobTitle = selectRandomly(jobTitlesArray);

// Return the formatted fortune string
return `You will be a ${jobTitle} in ${location}, married to ${partnerName} with ${numKids} kids.`;
}

function main() {
const numKids = [
// TODO add elements here
];

const partnerNames = [
// TODO add elements here
];

const locations = [
// TODO add elements here
];

const jobTitles = [
// TODO add elements here
];
const numKids = [0, 1, 2, 3, 4]; // Array of 5 possible numbers of kids
const partnerNames = ['Alice', 'Bob', 'Charlie', 'Dana', 'Eve']; // Array of 5 partner names
const locations = ['Amsterdam', 'Berlin', 'London', 'Paris', 'Rome']; // Array of 5 locations
const jobTitles = ['Engineer', 'Teacher', 'Designer', 'Chef', 'Artist']; // Array of 5 job titles

console.log(tellFortune(numKids, partnerNames, locations, jobTitles));
console.log(tellFortune(numKids, partnerNames, locations, jobTitles));
Expand Down
15 changes: 13 additions & 2 deletions 1-JavaScript/Week2/assignment/ex4-shoppingCart.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,19 @@ you have more than 3 items in your shopping cart the first item gets taken out.
const shoppingCart = ['bananas', 'milk'];

// ! Function to be tested
function addToShoppingCart(/* parameters go here */) {
// TODO complete this function
function addToShoppingCart(item) {
// If an item is provided, add it to the shopping cart
if (item !== undefined) {
shoppingCart.push(item);
}

// If there are more than 3 items, remove the first one
if (shoppingCart.length > 3) {
shoppingCart.shift();
}

// Return the comma-separated string
return `You bought ${shoppingCart.join(', ')}!`;
}

// ! Test functions (plain vanilla JavaScript)
Expand Down
13 changes: 11 additions & 2 deletions 1-JavaScript/Week2/assignment/ex5-shoppingCartPure.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ it pure. Do the following:
spread syntax.
5. Confirm that you function passes the provided unit tests.
------------------------------------------------------------------------------*/

// ! Function under test
function addToShoppingCart(/* TODO parameter(s) go here */) {
// TODO complete this function
function addToShoppingCart(shoppingCart, item) {
// Create a new array using spread syntax to avoid mutating the original
const newCart = [...shoppingCart, item];

// If more than 3 items, remove the first one
if (newCart.length > 3) {
newCart.shift();
}

return newCart;
}

// ! Test functions (plain vanilla JavaScript)
Expand Down
32 changes: 27 additions & 5 deletions 1-JavaScript/Week2/assignment/ex6-totalCost.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,45 @@ instead!

3. Complete the unit test functions and verify that all is working as expected.
-----------------------------------------------------------------------------*/

// Create an object with 5 grocery items
const cartForParty = {
// TODO complete this object
beers: 5.25,
chips: 1.5,
soda: 2.0,
cookies: 3.75,
cheese: 4.25,
};

function calculateTotalPrice(/* TODO parameter(s) go here */) {
// TODO replace this comment with your code
// Function to calculate total price of items in an object
function calculateTotalPrice(cart) {
let total = 0;

// Loop through object values and sum them
for (const item in cart) {
if (cart.hasOwnProperty(item)) {
total += cart[item];
}
}

// Return formatted total
return `Total: €${total.toFixed(2)}`;
}

// ! Test functions (plain vanilla JavaScript)
function test1() {
console.log('\nTest 1: calculateTotalPrice should take one parameter');
// TODO replace this comment with your code
console.assert(calculateTotalPrice.length === 1);
}

function test2() {
console.log('\nTest 2: return correct output when passed cartForParty');
// TODO replace this comment with your code
const expected = 'Total: €16.75';
const actual = calculateTotalPrice(cartForParty);
console.assert(
actual === expected,
`Expected "${expected}", but got "${actual}"`
);
}

function test() {
Expand Down
10 changes: 8 additions & 2 deletions 1-JavaScript/Week2/assignment/ex7-mindPrivacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ const employeeRecords = [
];

// ! Function under test
function filterPrivateData(/* TODO parameter(s) go here */) {
// TODO complete this function
function filterPrivateData(records) {
// Create a new array by mapping over the original records
return records.map((record) => {
// Destructure the non-private properties
const { name, occupation, email } = record;
// Return a new object with only the allowed properties
return { name, occupation, email };
});
}

// ! Test functions (plain vanilla JavaScript)
Expand Down
23 changes: 23 additions & 0 deletions 1-JavaScript/Week2/test-reports/ex1-giveCompliment.report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
*** Unit Test Error Report ***

PASS .dist/1-JavaScript/Week2/unit-tests/ex1-giveCompliment.test.js
js-wk2-ex1-giveCompliment
✅ should exist and be executable (2 ms)
✅ should have all TODO comments removed (1 ms)
✅ `giveCompliment` should not contain unneeded console.log calls (1 ms)
✅ should take a single parameter
✅ should include a `compliments` array inside its function body (1 ms)
✅ the `compliments` array should be initialized with 10 strings
✅ should give a random compliment: You are `compliment`, `name`! (1 ms)

Test Suites: 1 passed, 1 total
Tests: 7 passed, 7 total
Snapshots: 0 total
Time: 0.479 s, estimated 1 s
Ran all test suites matching /\/Users\/majdjadalhaq\/Desktop\/Assignments-Cohort54\/.dist\/1-JavaScript\/Week2\/unit-tests\/ex1-giveCompliment.test.js/i.
No linting errors detected.


*** Spell Checker Report ***

1-JavaScript/Week2/assignment/ex1-giveCompliment.js:30:19 - Unknown word (Majd)
19 changes: 19 additions & 0 deletions 1-JavaScript/Week2/test-reports/ex2-dogYears.report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*** Unit Test Error Report ***

PASS .dist/1-JavaScript/Week2/unit-tests/ex2-dogYears.test.js
js-wk2-ex2-dogYears
✅ should exist and be executable (1 ms)
✅ should have all TODO comments removed
✅ `calculateDogAge` should not contain unneeded console.log calls
✅ should take a single parameter
✅ should give 7 dog years for 1 human year
✅ should give 14 dog years for 2 human years
✅ give 21 dog years for 3 human years

Test Suites: 1 passed, 1 total
Tests: 7 passed, 7 total
Snapshots: 0 total
Time: 0.501 s
Ran all test suites matching /\/Users\/majdjadalhaq\/Desktop\/Assignments-Cohort54\/.dist\/1-JavaScript\/Week2\/unit-tests\/ex2-dogYears.test.js/i.
No linting errors detected.
No spelling errors detected.
22 changes: 22 additions & 0 deletions 1-JavaScript/Week2/test-reports/ex3-tellFortune.report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
*** Unit Test Error Report ***

PASS .dist/1-JavaScript/Week2/unit-tests/ex3-tellFortune.test.js
js-wk2-ex3-tellFortune
✅ should exist and be executable (2 ms)
✅ should have all TODO comments removed
✅ `tellFortune` should not contain unneeded console.log calls (1 ms)
✅ should take four parameters (1 ms)
✅ should call function `selectRandomly` for each of its arguments (1 ms)
✅ `numKids` should be an array initialized with 5 elements
✅ `locations` should be an array initialized with 5 elements (1 ms)
✅ `partnerNames` should be an array initialized with 5 elements
✅ `jobTitles` should be an array initialized with 5 elements (1 ms)
✅ should tell the fortune by randomly selecting array values (1 ms)

Test Suites: 1 passed, 1 total
Tests: 10 passed, 10 total
Snapshots: 0 total
Time: 0.523 s
Ran all test suites matching /\/Users\/majdjadalhaq\/Desktop\/Assignments-Cohort54\/.dist\/1-JavaScript\/Week2\/unit-tests\/ex3-tellFortune.test.js/i.
No linting errors detected.
No spelling errors detected.
3 changes: 3 additions & 0 deletions 1-JavaScript/Week2/test-reports/ex4-shoppingCart.report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A unit test file was not provided for this exercise.
No linting errors detected.
No spelling errors detected.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A unit test file was not provided for this exercise.
No linting errors detected.
No spelling errors detected.
3 changes: 3 additions & 0 deletions 1-JavaScript/Week2/test-reports/ex6-totalCost.report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A unit test file was not provided for this exercise.
No linting errors detected.
No spelling errors detected.
10 changes: 10 additions & 0 deletions 1-JavaScript/Week2/test-reports/ex7-mindPrivacy.report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
A unit test file was not provided for this exercise.
No linting errors detected.


*** Spell Checker Report ***

1-JavaScript/Week2/assignment/ex7-mindPrivacy.js:16:12 - Unknown word (majd)
1-JavaScript/Week2/assignment/ex7-mindPrivacy.js:23:12 - Unknown word (marit)
1-JavaScript/Week2/assignment/ex7-mindPrivacy.js:52:14 - Unknown word (majd)
1-JavaScript/Week2/assignment/ex7-mindPrivacy.js:57:14 - Unknown word (marit)