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 | - | - | ✓ |
49 changes: 20 additions & 29 deletions 1-JavaScript/Week2/assignment/ex1-giveCompliment.js
Original file line number Diff line number Diff line change
@@ -1,42 +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.
-----------------------------------------------------------------------------*/
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}!`;
}

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

const myName = "Rim";
console.log(giveCompliment(myName));
console.log(giveCompliment(myName));
console.log(giveCompliment(myName));

const yourName = 'Amsterdam';

const yourName = "Hadid";
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}!`;
}

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();
}

29 changes: 6 additions & 23 deletions 1-JavaScript/Week2/assignment/ex2-dogYears.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
/*------------------------------------------------------------------------------
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) {
const dogYears = humanYears * 7;
return `Your doggie is ${dogYears} years old in dog years!`;
}

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!"
console.log(calculateDogAge(1));
console.log(calculateDogAge(2));
console.log(calculateDogAge(3));
}

// ! Do not change or remove the code below
if (process.env.NODE_ENV !== 'test') {
main();
}
70 changes: 18 additions & 52 deletions 1-JavaScript/Week2/assignment/ex3-tellFortune.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,21 @@
/*------------------------------------------------------------------------------
Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week3#exercise-3-be-your-own-fortune-teller

Why pay a fortune teller when you can just program your fortune yourself?

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
function selectRandomly(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}

export function tellFortune(/* TODO add parameter(s) here */) {
// TODO complete this function
export function tellFortune(numKids, partnerNames, locations, jobTitles) {
return `You will be a ${selectRandomly(jobTitles)} in ${selectRandomly(
locations
)}, married to ${selectRandomly(partnerNames)} with ${selectRandomly(
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];
const partnerNames = ["Alex", "Sam", "Taylor", "Jordan", "Casey"];
const locations = ["Amsterdam", "Rotterdam", "Utrecht", "The Hague", "Eindhoven"];
const jobTitles = ["developer", "designer", "teacher", "engineer", "chef"];

console.log(tellFortune(numKids, partnerNames, locations, jobTitles));
console.log(tellFortune(numKids, partnerNames, locations, jobTitles));
Expand All @@ -66,3 +26,9 @@ function main() {
if (process.env.NODE_ENV !== 'test') {
main();
}






59 changes: 22 additions & 37 deletions 1-JavaScript/Week2/assignment/ex4-shoppingCart.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,41 @@
/*------------------------------------------------------------------------------
Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week3#exercise-4-shopping-at-the-supermarket

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
function addToShoppingCart(item) {
if (item !== undefined) {
shoppingCart.push(item);
if (shoppingCart.length > 3) {
shoppingCart.shift();
}
}
return `You bought ${shoppingCart.join(', ')}!`;
}

// ! Test functions (plain vanilla JavaScript)
// ===== manual tests (restore) =====
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.log('Test 1: add `chocolate` to the cart');
const expected = 'You bought bananas, milk, chocolate!';
const actual = addToShoppingCart('chocolate');
console.assert(actual === expected);
}

function test2() {
console.log('Test 2: addShoppingCart() should take one parameter');
const expected = 1;
const actual = addToShoppingCart.length;
console.log('Test 2: add `waffles` (keep last 3 items)');
const expected = 'You bought milk, chocolate, waffles!';
const actual = addToShoppingCart('waffles');
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.log('Test 3: add `tea` (bananas removed)');
const expected = 'You bought chocolate, waffles, tea!';
const actual = addToShoppingCart('tea');
console.assert(actual === expected);
}

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.log('Test 4: add nothing (cart unchanged)');
const expected = 'You bought chocolate, waffles, tea!';
const actual = addToShoppingCart();
console.assert(actual === expected);
}

Expand All @@ -69,4 +54,4 @@ function test() {
test5();
}

test();
test();
Loading