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 | - | - | ✓ |
21 changes: 18 additions & 3 deletions 1-JavaScript/Week2/assignment/ex1-giveCompliment.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@ Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-J
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 = [
'doing great',
'beautiful',
'doing a fantastic job',
'strong',
'more prepared than you feel',
'quite smart',
'making amazing progress',
'smart',
'growing stronger with every step',
'becoming a better developer every day',
]

const randomIndex = Math.floor(Math.random() * compliments.length)
const randomCompliment = compliments[randomIndex]

return `You are ${randomCompliment}, ${name}!`;
}

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

console.log(giveCompliment(myName));
Expand Down
5 changes: 3 additions & 2 deletions 1-JavaScript/Week2/assignment/ex2-dogYears.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ calculate it!
ages.
-----------------------------------------------------------------------------*/

export function calculateDogAge(/* TODO parameter(s) go here */) {
// TODO complete this function
export function calculateDogAge(humanAge){
const dogAge = humanAge * 7
return `Your doggie is ${dogAge} years old in dog years!`
}

function main() {
Expand Down
36 changes: 26 additions & 10 deletions 1-JavaScript/Week2/assignment/ex3-tellFortune.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,45 @@ 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) {
const randomIndex = Math.floor(Math.random() * arr.length)
return arr[randomIndex]
}

export function tellFortune(/* TODO add parameter(s) here */) {
// TODO complete this function
export function tellFortune(numKids, partnerNames, locations, jobTitles) {
const kids = selectRandomly(numKids)
const partner = selectRandomly(partnerNames)
const location = selectRandomly(locations)
const job = selectRandomly(jobTitles)

return `You will be a ${job} in ${location}, married to ${partner} with ${kids} kids.`
}

function main() {
const numKids = [
// TODO add elements here
];
const numKids = [1, 2, 3, 4, 5];

const partnerNames = [
// TODO add elements here
'Sharon',
'Anna',
'Veronika',
'Stacy',
'Jennie'
];

const locations = [
// TODO add elements here
'Amsterdam',
'Haarlem',
'Paris',
'Rotterdam',
'Groningen'
];

const jobTitles = [
// TODO add elements here
'Front dev',
'Back dev',
'DevOps',
'Q&A',
'Cleaner'
];

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

const listOfProducts = shoppingCart.join(', ')

return `You bought ${listOfProducts}!`
}

// ! Test functions (plain vanilla JavaScript)
Expand Down
15 changes: 13 additions & 2 deletions 1-JavaScript/Week2/assignment/ex5-shoppingCartPure.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ it pure. Do the following:
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(arrOfFruits, item) {
const ownArrOfFruits = [...arrOfFruits]

if (typeof item === 'undefined') {
return ownArrOfFruits
}

ownArrOfFruits.push(item)
if (ownArrOfFruits.length > 3) {
ownArrOfFruits.shift()
}

return ownArrOfFruits
}

// ! Test functions (plain vanilla JavaScript)
Expand Down
24 changes: 19 additions & 5 deletions 1-JavaScript/Week2/assignment/ex6-totalCost.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,36 @@ instead!
3. Complete the unit test functions and verify that all is working as expected.
-----------------------------------------------------------------------------*/
const cartForParty = {
// TODO complete this object
beer: 10,
chips: 5,
iceCream: 5.99,
water: 4.50,
salads: 19.25
};

function calculateTotalPrice(/* TODO parameter(s) go here */) {
// TODO replace this comment with your code
function calculateTotalPrice(cartObj) {
let finalPrice = 0

for (let item in cartObj) {
finalPrice += cartObj[item]
}

return `Total: ${finalPrice.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
const expected = 1
const actual = calculateTotalPrice.length
console.assert(expected === actual)
}

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

function test() {
Expand Down
7 changes: 5 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,11 @@ const employeeRecords = [
];

// ! Function under test
function filterPrivateData(/* TODO parameter(s) go here */) {
// TODO complete this function
function filterPrivateData(employeeArray) {
return employeeArray.map(employee => {
const { name, occupation, email } = employee
return { name, occupation, email }
})
}

// ! Test functions (plain vanilla JavaScript)
Expand Down
19 changes: 19 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,19 @@
*** Unit Test Error Report ***

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

Test Suites: 1 passed, 1 total
Tests: 7 passed, 7 total
Snapshots: 0 total
Time: 0.29 s, estimated 1 s
Ran all test suites matching /\/Users\/dimadoronin\/Documents\/Programming\/HackYourFuture\/Assignments-Cohort54\/.dist\/1-JavaScript\/Week2\/unit-tests\/ex1-giveCompliment.test.js/i.
No linting errors detected.
No spelling errors detected.
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
✅ should have all TODO comments removed
✅ `calculateDogAge` should not contain unneeded console.log calls
✅ should take a single parameter (1 ms)
✅ 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.572 s
Ran all test suites matching /\/Users\/dimadoronin\/Documents\/Programming\/HackYourFuture\/Assignments-Cohort54\/.dist\/1-JavaScript\/Week2\/unit-tests\/ex2-dogYears.test.js/i.
No linting errors detected.
No spelling errors detected.
26 changes: 26 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,26 @@
*** Unit Test Error Report ***

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

Test Suites: 1 passed, 1 total
Tests: 10 passed, 10 total
Snapshots: 0 total
Time: 0.216 s, estimated 1 s
Ran all test suites matching /\/Users\/dimadoronin\/Documents\/Programming\/HackYourFuture\/Assignments-Cohort54\/.dist\/1-JavaScript\/Week2\/unit-tests\/ex3-tellFortune.test.js/i.
No linting errors detected.


*** Spell Checker Report ***

1-JavaScript/Week2/assignment/ex3-tellFortune.js:55:6 - Unknown word (Veronika)
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.
3 changes: 3 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,3 @@
A unit test file was not provided for this exercise.
No linting errors detected.
No spelling errors detected.