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 | 3 | 4 | ✓ |
| ex2-dogYears | 4 | 3 | ✓ |
| ex3-tellFortune | 7 | 3 | ✓ |
| ex4-shoppingCart | - | - | ✓ |
| ex5-shoppingCartPure | - | - | ✓ |
| ex6-totalCost | - | - | ✓ |
| ex7-mindPrivacy | - | - | ✓ |
41 changes: 18 additions & 23 deletions 1-JavaScript/Week2/assignment/ex1-giveCompliment.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,35 @@ Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-J

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.
-----------------------------------------------------------------------------*/
export function giveCompliment(/* TODO parameter(s) go here */) {
// TODO complete this function
export function giveCompliment(name) {
const compliments = [
"great",
"awesome",
"fantastic",
"brilliant",
"wonderful",
"amazing",
"incredible",
"outstanding",
"marvelous",
"exceptional"
];
const i = Math.floor(Math.random() * compliments.length);
return `You are ${compliments[i]}, ${name}!`;
Comment on lines +6 to +20

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!
The only minor comment I have here is that it's good practice to maintain the indentation (line 6) to make the code readable and maintainable
** I just saw that in the duplicate file you made the fix. 😄

}

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

const myName = "HackYourFuture";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to read the assignment instructions and check if your code meets the requirements.
In this case, it was requested to replace the string "HackYourFuture" with your name.

console.log(giveCompliment(myName));
console.log(giveCompliment(myName));
console.log(giveCompliment(myName));

const yourName = 'Amsterdam';

const yourName = "Amsterdam";
console.log(giveCompliment(yourName));
console.log(giveCompliment(yourName));
console.log(giveCompliment(yourName));
}

// ! Do not change or remove the code below
if (process.env.NODE_ENV !== 'test') {
if (process.env.NODE_ENV !== "test") {
main();
}
68 changes: 68 additions & 0 deletions 1-JavaScript/Week2/assignment/ex1-giveCompliment1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
export const compliments = [
"great",
"awesome",
"fantastic",
"brilliant",
"wonderful",
"amazing",
"incredible",
"outstanding",
"marvelous",
"exceptional"
];

export function giveCompliment(name) {
const i = Math.floor(Math.random() * compliments.length);
return `You are ${compliments[i]}, ${name}!`;
}
Comment on lines +14 to +17

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate file of the previous one. It's good practice to clean up your files before submitting your assignments.


function main() {
const myName = "HackYourFuture";
console.log(giveCompliment(myName));
console.log(giveCompliment(myName));
console.log(giveCompliment(myName));

const yourName = "Amsterdam";
console.log(giveCompliment(yourName));
console.log(giveCompliment(yourName));
console.log(giveCompliment(yourName));
}

if (process.env.NODE_ENV !== "test") {
main();
}
1. Complete the function named `giveCompliment`as follows:

export function giveCompliment(name) {
const compliments = [
"great",
"awesome",
"fantastic",
"brilliant",
"wonderful",
"amazing",
"incredible",
"outstanding",
"marvelous",
"exceptional"
];
const i = Math.floor(Math.random() * compliments.length);
return `You are ${compliments[i]}, ${name}!`;
}

function main() {
const myName = "HackYourFuture";
console.log(giveCompliment(myName));
console.log(giveCompliment(myName));
console.log(giveCompliment(myName));

const yourName = "Amsterdam";
console.log(giveCompliment(yourName));
console.log(giveCompliment(yourName));
console.log(giveCompliment(yourName));
}

if (process.env.NODE_ENV !== "test") {
main();
}

37 changes: 13 additions & 24 deletions 1-JavaScript/Week2/assignment/ex2-dogYears.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
/*------------------------------------------------------------------------------
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!
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
export function calculateDogAge(humanYears) {
return humanYears * 7;
Comment on lines +1 to +2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice try. You are almost there.

Take another look at the requirements, the function should return a string. What does your function 'calculateDogAge' return?

}

function main() {
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!"
const myAge = 25;
console.log(
`If you are ${myAge} years old, that's ${calculateDogAge(myAge)} in dog years!`
);

const yourAge = 40;
console.log(
`If you are ${yourAge} years old, that's ${calculateDogAge(yourAge)} in dog years!`
);
Comment on lines +6 to +14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary, the function 'calculateDogAge' should return the console.log(). Think about the string that is the expected result, and where in the code it should be triggered.

}

// ! Do not change or remove the code below
if (process.env.NODE_ENV !== 'test') {
if (process.env.NODE_ENV !== "test") {
main();
}

72 changes: 13 additions & 59 deletions 1-JavaScript/Week2/assignment/ex3-tellFortune.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,22 @@
/*------------------------------------------------------------------------------
Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week3#exercise-3-be-your-own-fortune-teller
export function tellFortune() {
const numKids = [0, 1, 2, 3, 4];
const partnerNames = ["Alex", "Sam", "Taylor", "Jordan", "Casey"];
const locations = ["Amsterdam", "Rotterdam", "Utrecht", "The Hague", "Eindhoven"];
const jobs = ["developer", "designer", "teacher", "engineer", "chef"];

Why pay a fortune teller when you can just program your fortune yourself?
const pick = (arr) => arr[Math.floor(Math.random() * arr.length)];
Comment on lines +1 to +7

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read the instructions carefully, think about the requirements, and try this exercise again.
The following are missing from the solution:

  • The selectRandomly() function is not present.
  • The tellFortune() function does not accept any arguments, and the requirements ask for 4 arguments.
  • The tellFortune() function should use the 'selectRandomly()' function to select values at random from the arrays.
  • In order to pass the tests, the 'jobs' array should be labeled as 'jobTitles'


1. Create four arrays, `numKids`, `partnerNames`, `locations` and `jobTitles`.
Give each array five random values that have to do with the name of
the variable.
2. Complete the function `selectRandomly`. This function should take an array
as a parameter and return a randomly selected element as its return value.
3. Complete the function named `tellFortune` as follows:
- It should take four arguments (in the order listed):
* the array with the options for the number of children,
* the array with the options for the partner's name,
* the array with the options for the geographic location and
* the array with the options for the job title.
- It should use the `selectRandomly` function to randomly select values from
the arrays.
- It should return a string: "You will be a `jobTitle` in `location`,
married to `partnerName` with `numKids` kids."
4. Call the function three times, passing the arrays as arguments. Use `
console.log` to display the results.
Note: The DRY principle is put into practice here: instead of repeating the code to
randomly select array elements four times inside the `tellFortune` function
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
}

export function tellFortune(/* TODO add parameter(s) here */) {
// TODO complete this function
return `You will be a ${pick(jobs)} in ${pick(locations)}, and married to ${pick(partnerNames)} with ${pick(numKids)} kids.`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good effort, you are almost there.

}

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
];

console.log(tellFortune(numKids, partnerNames, locations, jobTitles));
console.log(tellFortune(numKids, partnerNames, locations, jobTitles));
console.log(tellFortune(numKids, partnerNames, locations, jobTitles));
console.log(tellFortune());
console.log(tellFortune());
console.log(tellFortune());
Comment on lines +13 to +15

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be a good idea to keep this as it was before.

}

// ! Do not change or remove the code below
if (process.env.NODE_ENV !== 'test') {
if (process.env.NODE_ENV !== "test") {
main();
}


77 changes: 17 additions & 60 deletions 1-JavaScript/Week2/assignment/ex4-shoppingCart.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,25 @@ Let's do some grocery shopping! We're going to get some things to cook dinner
with. However, you like to spend money and always buy too many things. So when
you have more than 3 items in your shopping cart the first item gets taken out.

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

- It should take one argument: a grocery item (string)
- It should add the grocery item to the `shoppingCart` array. If the number of items is
more than three remove the first one in the array.
- It should return a string "You bought <list-of-items>!", where
<list-of-items>is a comma-separated list of items from the shopping cart
array.

2. Confirm that your code passes the unit tests.
-----------------------------------------------------------------------------*/
const shoppingCart = ['bananas', 'milk'];

// ! Function to be tested
function addToShoppingCart(/* parameters go here */) {
// TODO complete this function
}

// ! Test functions (plain vanilla JavaScript)
function test1() {
console.log(
'Test 1: addShoppingCart() called without an argument should leave the shopping cart unchanged'
);
const expected = 'You bought bananas, milk!';
const actual = addToShoppingCart();
console.assert(actual === expected);
}

function test2() {
console.log('Test 2: addShoppingCart() should take one parameter');
const expected = 1;
const actual = addToShoppingCart.length;
console.assert(actual === expected);
}

function test3() {
console.log('Test 3: `chocolate` should be added');
const expected = 'You bought bananas, milk, chocolate!';
const actual = addToShoppingCart('chocolate');
console.assert(actual === expected);
const shoppingCart = ["bananas", "milk"];

export function addToShoppingCart(item) {
if (item !== undefined) {
shoppingCart.push(item);
if (shoppingCart.length > 3) {
shoppingCart.shift();
}
}
return `You bought ${shoppingCart.join(", ")}!`;
Comment on lines +8 to +17

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way to go! 🚀

Line 10: Think about what types of situations where 'export' would be used. Is it applicable in this case?

}

function test4() {
console.log('Test 4: `waffles` should be added and `bananas` removed');
const expected = 'You bought milk, chocolate, waffles!';
const actual = addToShoppingCart('waffles');
console.assert(actual === expected);
function main() {
console.log(addToShoppingCart());
console.log(addToShoppingCart("chocolate"));
console.log(addToShoppingCart("waffles"));
console.log(addToShoppingCart("tea"));
}

function test5() {
console.log('Test 5: `tea` should be added and `milk` removed');
const expected = 'You bought chocolate, waffles, tea!';
const actual = addToShoppingCart('tea');
console.assert(actual === expected);
if (process.env.NODE_ENV !== "test") {
main();
}

function test() {
test1();
test2();
test3();
test4();
test5();
}

test();
Comment on lines -57 to -72

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please restore this code, see above.

Loading