-
Notifications
You must be signed in to change notification settings - Fork 0
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
Java script week3 #1
base: main
Are you sure you want to change the base?
Changes from 6 commits
9d8a002
9dc6857
56b0c0a
c19428b
bc795fd
ecefef1
be7330b
1257598
b95b748
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,10 @@ calculate it! | |
ages. | ||
-----------------------------------------------------------------------------*/ | ||
|
||
function calculateDogAge(/* parameters go here */) { | ||
function calculateDogAge(age) { | ||
// TODO complete this function | ||
age = age * 7; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can remove the
or
|
||
return `Your doggie is ${age} years old in dog years!`; | ||
} | ||
|
||
console.log(calculateDogAge(1)); // -> "Your doggie is 7 years old in dog years!" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,28 +27,56 @@ body, this code is now written once only in a separated function. | |
-----------------------------------------------------------------------------*/ | ||
const numKids = [ | ||
// TODO add elements here | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
]; | ||
|
||
const partnerNames = [ | ||
// TODO add elements here | ||
'Thomas', | ||
'James', | ||
'Mia', | ||
'Ruby', | ||
'Scarlett', | ||
]; | ||
|
||
const locations = [ | ||
// TODO add elements here | ||
'Amsterdam', | ||
'Utrecht', | ||
'Rotterdam', | ||
'Den Haag', | ||
'Leiden', | ||
]; | ||
|
||
const jobTitles = [ | ||
// TODO add elements here | ||
'Director', | ||
'Manager', | ||
'Administrator', | ||
'Web administrator', | ||
'Zoologist', | ||
]; | ||
|
||
// 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 */) { | ||
function selectRandomly(arr) { | ||
// TODO complete this function | ||
const index = Math.floor(Math.random() * 5); | ||
return arr[index]; | ||
} | ||
|
||
function tellFortune(/* add parameter(s) here */) { | ||
function tellFortune(num, name, address, job) { | ||
// TODO complete this function | ||
const jobTitle = selectRandomly(job); | ||
const numKids = selectRandomly(num); | ||
const location = selectRandomly(address); | ||
const partnerName = selectRandomly(name); | ||
|
||
return `You will be a ${jobTitle} in ${location}, married to ${partnerName} with ${numKids} kids.`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
|
||
console.log(tellFortune(numKids, partnerNames, locations, jobTitles)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,21 @@ you have more than 3 items in your shopping cart the first item gets taken out. | |
-----------------------------------------------------------------------------*/ | ||
const shoppingCart = ['bananas', 'milk']; | ||
|
||
function addToShoppingCart(/* parameters go here */) { | ||
function addToShoppingCart(groceryItem) { | ||
// TODO complete this function | ||
if (shoppingCart.length < 3) { | ||
shoppingCart.push(groceryItem); | ||
} else { | ||
shoppingCart.shift(); | ||
shoppingCart.push(groceryItem); | ||
} | ||
const groceriesString = shoppingCart.join(', '); | ||
return `You bought ${groceriesString}!`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
|
||
addToShoppingCart('chocolate'); // Returns "You bought bananas, milk, chocolate!" | ||
addToShoppingCart('waffles'); // Returns "You bought milk, chocolate, waffles!" | ||
addToShoppingCart('tea'); // Returns "You bought chocolate, waffles, tea!" | ||
console.log(addToShoppingCart('chocolate')); // Returns "You bought bananas, milk, chocolate!" | ||
console.log(addToShoppingCart('waffles')); // Returns "You bought milk, chocolate, waffles!" | ||
console.log(addToShoppingCart('tea')); // Returns "You bought chocolate, waffles, tea!" | ||
|
||
// ! Do not change or remove any code below | ||
module.exports = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,16 @@ it pure. Do the following: | |
4. When constructing the new shopping cart array you should make use of the ES5 | ||
spread syntax. | ||
------------------------------------------------------------------------------*/ | ||
function addToShoppingCart(/* TODO parameter(s) go here */) { | ||
function addToShoppingCart(arr, groceryItem) { | ||
// TODO complete this function | ||
const newArr = [...arr]; | ||
if (newArr.length < 3) { | ||
newArr.push(groceryItem); | ||
} else { | ||
newArr.shift(); | ||
newArr.push(groceryItem); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if you did this instead? A bit cleaner, right?
|
||
return newArr; | ||
} | ||
|
||
const shoppingCart = ['bananas', 'milk']; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,22 @@ instead! | |
Use `console.log` to display the result. | ||
-----------------------------------------------------------------------------*/ | ||
const cartForParty = { | ||
// TODO complete this function | ||
beers: 1.1, | ||
chips: 2.9, | ||
cola: 2.3, | ||
olives: 2.7, | ||
bacon: 2, //11.00 | ||
}; | ||
|
||
function calculateTotalPrice(/* TODO parameter(s) go here */) { | ||
// TODO replace this comment with your code | ||
function calculateTotalPrice(cart) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Veronica - although this logic works fine but you could improve it slightly. Firstly, you should try to avoid using
|
||
let totalPrice = 0; | ||
for (const key in cart) { | ||
totalPrice = totalPrice + cart[key]; | ||
} | ||
totalPrice = totalPrice.toFixed(2); | ||
return `Total: €${totalPrice}`; | ||
} | ||
console.log(calculateTotalPrice(cartForParty)); | ||
|
||
// this is one example, you will need to write a different object | ||
calculateTotalPrice({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,15 @@ const employeeRecords = [ | |
}, | ||
]; | ||
|
||
function filterPrivateData(/* parameter(s) go here */) { | ||
function filterPrivateData(arrEmployees) { | ||
// TODO complete this function | ||
const newArrEmployees = []; | ||
for (const employee of arrEmployees) { | ||
const { name, occupation, email } = employee; | ||
const employeeNew = { name, occupation, email }; | ||
newArrEmployees.push(employeeNew); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🆗 |
||
} | ||
return newArrEmployees; | ||
} | ||
|
||
console.log(filterPrivateData(employeeRecords)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
All tests passed |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
All tests passed |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
All tests passed |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
All tests passed |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
All tests passed |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
All tests passed |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
All tests passed |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"node": "v14.15.4", | ||
"system": { | ||
"manufacturer": "Acer", | ||
"model": "Aspire ES1-331" | ||
}, | ||
"cpu": { | ||
"manufacturer": "Intel®", | ||
"brand": "Pentium® N3700", | ||
"speed": 1.6, | ||
"virtualization": true | ||
}, | ||
"memory": "8 GB", | ||
"osInfo": { | ||
"platform": "win32", | ||
"distro": "Microsoft Windows 10 Home Single Language", | ||
"release": "10.0.18363" | ||
}, | ||
"blockDevices": [ | ||
{ | ||
"name": "C:", | ||
"size": "499 GB", | ||
"fsType": "ntfs", | ||
"physical": "Local" | ||
} | ||
], | ||
"vscodeInfo": { | ||
"version": "1.53.0", | ||
"extensions": [ | ||
"CoenraadS.bracket-pair-colorizer", | ||
"dbaeumer.vscode-eslint", | ||
"esbenp.prettier-vscode", | ||
"evgeniypeshkov.syntax-highlighter", | ||
"formulahendry.code-runner", | ||
"hdg.live-html-previewer", | ||
"ritwickdey.LiveServer", | ||
"streetsidesoftware.code-spell-checker", | ||
"techer.open-in-browser" | ||
], | ||
"userSettings": { | ||
"editor.detectIndentation": false, | ||
"editor.formatOnSave": true, | ||
"editor.minimap.enabled": false, | ||
"editor.renderIndentGuides": true, | ||
"editor.tabSize": 2, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll": true | ||
}, | ||
"eslint.autoFixOnSave": true, | ||
"files.autoSave": "onFocusChange", | ||
"prettier.singleQuote": true, | ||
"prettier.trailingComma": "all", | ||
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe", | ||
"workbench.colorTheme": "Visual Studio Light", | ||
"window.zoomLevel": 1 | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
2021-02-10 06:20:02 info: ---------------------------------------------- | ||
2021-02-10 06:20:02 info: >>> Running Unit Test `ex1-giveCompliment` <<< | ||
2021-02-10 06:20:02 info: ---------------------------------------------- | ||
2021-02-10 06:20:50 error: *** Unit Test Error Report *** | ||
|
||
|
||
|
||
2021-02-10 06:22:38 info: Disclaimer turned off | ||
2021-02-10 06:27:32 info: ---------------------------------------------- | ||
2021-02-10 06:27:32 info: >>> Running Unit Test `ex1-giveCompliment` <<< | ||
2021-02-10 06:27:32 info: ---------------------------------------------- | ||
2021-02-10 06:27:54 info: All unit tests passed. | ||
2021-02-10 06:28:05 info: All steps were completed successfully | ||
2021-02-10 07:21:59 info: ---------------------------------------- | ||
2021-02-10 07:21:59 info: >>> Running Unit Test `ex2-dogYears` <<< | ||
2021-02-10 07:21:59 info: ---------------------------------------- | ||
2021-02-10 07:22:17 info: All unit tests passed. | ||
2021-02-10 07:22:31 info: All steps were completed successfully | ||
2021-02-11 10:24:25 info: ------------------------------------------- | ||
2021-02-11 10:24:25 info: >>> Running Unit Test `ex3-tellFortune` <<< | ||
2021-02-11 10:24:25 info: ------------------------------------------- | ||
2021-02-11 10:25:14 info: All unit tests passed. | ||
2021-02-11 10:25:37 error: *** Spell Checker Report *** | ||
|
||
ex3-tellFortune.js:43:4 - Unknown word (Scarlett) | ||
ex3-tellFortune.js:51:8 - Unknown word (Haag) | ||
|
||
2021-02-11 11:07:31 info: ------------------------------------------- | ||
2021-02-11 11:07:31 info: >>> Running Unit Test `ex3-tellFortune` <<< | ||
2021-02-11 11:07:31 info: ------------------------------------------- | ||
2021-02-11 11:08:29 error: *** Unit Test Error Report *** | ||
|
||
|
||
|
||
2021-02-11 11:09:26 info: ------------------------------------------- | ||
2021-02-11 11:09:26 info: >>> Running Unit Test `ex3-tellFortune` <<< | ||
2021-02-11 11:09:26 info: ------------------------------------------- | ||
2021-02-11 11:09:53 info: All unit tests passed. | ||
2021-02-11 11:10:05 info: All steps were completed successfully | ||
2021-02-11 11:44:24 info: -------------------------------------------- | ||
2021-02-11 11:44:24 info: >>> Running Unit Test `ex4-shoppingCart` <<< | ||
2021-02-11 11:44:24 info: -------------------------------------------- | ||
2021-02-11 11:44:44 info: All unit tests passed. | ||
2021-02-11 11:44:57 info: All steps were completed successfully | ||
2021-02-12 12:06:22 info: ------------------------------------------------- | ||
2021-02-12 12:06:22 info: >>> Running Unit Test `ex5-shoppingCartRedux` <<< | ||
2021-02-12 12:06:22 info: ------------------------------------------------- | ||
2021-02-12 12:06:43 info: All unit tests passed. | ||
2021-02-12 12:06:55 info: All steps were completed successfully | ||
2021-02-12 12:29:45 info: ----------------------------------------- | ||
2021-02-12 12:29:45 info: >>> Running Unit Test `ex6-totalCost` <<< | ||
2021-02-12 12:29:45 info: ----------------------------------------- | ||
2021-02-12 12:30:04 error: *** Unit Test Error Report *** | ||
|
||
- calculateTotalPrice cartForParty should contain five grocery items with prices | ||
- calculateTotalPrice should return the total price in Euros | ||
Expected: Total: €12.00 | ||
Received: Total: €12 | ||
|
||
2021-02-12 12:33:02 info: ----------------------------------------- | ||
2021-02-12 12:33:02 info: >>> Running Unit Test `ex6-totalCost` <<< | ||
2021-02-12 12:33:02 info: ----------------------------------------- | ||
2021-02-12 12:33:19 info: All unit tests passed. | ||
2021-02-12 12:33:31 info: All steps were completed successfully | ||
2021-02-12 11:29:19 info: ------------------------------------------- | ||
2021-02-12 11:29:19 info: >>> Running Unit Test `ex7-mindPrivacy` <<< | ||
2021-02-12 11:29:19 info: ------------------------------------------- | ||
2021-02-12 11:29:37 info: All unit tests passed. | ||
2021-02-12 11:29:49 info: All steps were completed successfully | ||
2021-02-15 12:27:15 info: ----------------------------------------- | ||
2021-02-15 12:27:15 info: >>> Running Unit Test `ex6-totalCost` <<< | ||
2021-02-15 12:27:15 info: ----------------------------------------- | ||
2021-02-15 12:27:55 error: *** Unit Test Error Report *** | ||
|
||
|
||
|
||
2021-02-15 12:28:33 info: ----------------------------------------- | ||
2021-02-15 12:28:33 info: >>> Running Unit Test `ex6-totalCost` <<< | ||
2021-02-15 12:28:33 info: ----------------------------------------- | ||
2021-02-15 12:28:57 info: All unit tests passed. | ||
2021-02-15 12:29:09 info: All steps were completed successfully |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nicely done and good use of variables.