-
-
Notifications
You must be signed in to change notification settings - Fork 265
LND10 | Adrian Ilovan | JS2-Coursework-Week1 #266
base: main
Are you sure you want to change the base?
Changes from all commits
4a82c54
8ec2fc6
d744786
f567656
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 |
|---|---|---|
|
|
@@ -21,7 +21,8 @@ let basketballTeam = { | |
| */ | ||
|
|
||
| // write code here | ||
|
|
||
| let sortedPlayers = basketballTeam.topPlayers.sort(); | ||
| sortedPlayers.forEach(player => console.log(player)); | ||
|
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. good use of foreach
Author
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. Thank you :) |
||
|
|
||
| /* EXPECTED RESULT | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,9 @@ | |
|
|
||
| let student = { | ||
| // write code here | ||
| getName: function(name) { | ||
| console.log(`Student name: ${name}`) | ||
| } | ||
| } | ||
|
|
||
|
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. Nice job with the exercises!
Author
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. Appreciated |
||
| student.getName("Daniel"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,4 +22,77 @@ | |
| You should write and log at least 5 recipes | ||
| */ | ||
|
|
||
| // write code here | ||
| // write code here | ||
|
|
||
| // First Recipe | ||
| const recipe1 = { | ||
| title: "Mole", | ||
| servings: 2, | ||
| ingredients: ["cinnamon", "cumin", "cocoa"] | ||
| }; | ||
|
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. So this looks good, no issues with your objects. But you could try to do this as a nested object instead?
Author
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. Will do! |
||
|
|
||
| console.log(recipe1.title); | ||
| console.log(`Serves: ${recipe1.servings}`); | ||
| console.log("Ingredients: "); | ||
| for (let i = 0; i < recipe1.ingredients.length; i++) { | ||
| console.log(recipe1.ingredients[i]); | ||
| } | ||
|
|
||
| // Second recipe | ||
| const recipe2 = { | ||
| title: "Pasta Bolognese", | ||
| servings: 3, | ||
| ingredients:["pasta", "onion", "garlic", "500g beef mince", "tomato sos", "olive oil"] | ||
| }; | ||
|
|
||
| console.log(recipe2.title); | ||
| console.log(`Serves: ${recipe2.servings}`); | ||
| console.log("Ingredients: "); | ||
| for (let i = 0; i < recipe2.ingredients.length; i++) { | ||
| console.log(recipe2.ingredients[i]); | ||
| } | ||
|
|
||
| // Third Recipe | ||
|
|
||
| const recipe3 = { | ||
| title: "Pizza", | ||
| servings: 4, | ||
| ingredients: ["dough", "salami", "tomato sos", "ham", "cheese"] | ||
| }; | ||
|
|
||
| console.log(recipe3.title); | ||
| console.log(`Serves ${recipe3.servings}`); | ||
| console.log("Ingredients: "); | ||
| for (let i = 0; i < recipe3.ingredients.length; i++) { | ||
| console.log(recipe3.ingredients[i]); | ||
| } | ||
|
|
||
| // Forth Recipe | ||
|
|
||
| const recipe4 = { | ||
| title: "Snitzels and chips", | ||
| servings: 3, | ||
| ingredients: ["chicken breast", "eggs", "flour", "oil", "potatos"] | ||
| }; | ||
|
|
||
| console.log(recipe4.title); | ||
| console.log(`Serves ${recipe4.servings}`); | ||
| console.log("Ingredients: "); | ||
| for (let i = 0; i < recipe4.ingredients.length; i++) { | ||
| console.log(recipe4.ingredients[i]); | ||
| } | ||
|
|
||
| //Fifth Recipe | ||
|
|
||
| const recipe5 = { | ||
| title: "Meatballs pasta", | ||
| servings: 3, | ||
| ingredients: ["beef", "pasta", "tomato sos", "garlic", "oil"] | ||
| }; | ||
|
|
||
| console.log(recipe5.title); | ||
| console.log(`Serves ${recipe5.servings}`); | ||
| console.log("Ingredients: "); | ||
| for (let i = 0; i < recipe5.ingredients.length; i++) { | ||
| console.log(recipe5.ingredients[i]); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,20 @@ let pantry = { | |
|
|
||
| function createShoppingList(recipe) { | ||
| // write code here | ||
|
|
||
| let missingItems = []; | ||
|
|
||
| for (let i = 0; i < recipe.ingredients.length; i++) { | ||
| let ingredient = recipe.ingredients[i]; | ||
| if (!pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(ingredient)) { | ||
|
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. This looks good! Nice use of ! and &&
Author
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. Had problems with this one and checked GPT for help |
||
| missingItems.push(ingredient); | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| name: recipe.name, | ||
| items: missingItems, | ||
| }; | ||
| } | ||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,20 @@ const MENU = { | |
|
|
||
| let cashRegister = { | ||
| // write code here | ||
| orderBurger(balance) { | ||
|
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. nice job! Very clean writing of this function
Author
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. ta :) |
||
| if (balance >= MENU.burger) { | ||
| balance -= MENU.burger; | ||
| } | ||
| return balance; | ||
| }, | ||
|
|
||
| orderFalafel(balance) { | ||
| if (balance >= MENU.falafel) { | ||
| balance -= MENU.falafel; | ||
| } | ||
| return balance; | ||
| } | ||
| }; | ||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== | ||
| - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,41 +35,57 @@ function convertScoreToGrade(score) { | |
| passes. | ||
| */ | ||
| test("a score of 83 is grade A", () => { | ||
| expect(convertScoreToGrade(83), "Z"); | ||
| expect(convertScoreToGrade(83)).toEqual("A"); | ||
| }); | ||
|
|
||
| /* | ||
| The rest of the tests have comments describing what to test and you need to | ||
| write a matching test | ||
| */ | ||
|
|
||
| test.skip("a score of 71 is grade B", () => { | ||
| test("a score of 71 is grade B", () => { | ||
| expect(convertScoreToGrade(71)).toEqual("B"); | ||
| /* Remove the .skip above, then write the test body. */ | ||
| }); | ||
| /* | ||
| Write a test that checks a score of 68 is grade C | ||
| */ | ||
|
|
||
| test("a score of 68 is grade C", () => { | ||
| expect(convertScoreToGrade(68)).toEqual("C"); | ||
| }); | ||
| /* | ||
| Write a test that checks a score of 55 is grade D | ||
| */ | ||
|
|
||
| test("a score of 55 is grade D", () => { | ||
| expect(convertScoreToGrade(55)).toEqual("D"); | ||
| }); | ||
| /* | ||
| Write a test that checks a score of 68 is grade C | ||
| */ | ||
|
|
||
| test("a score of 68 is grade C", () => { | ||
| expect(convertScoreToGrade(68)).toEqual("C"); | ||
| }); | ||
| /* | ||
| Write a test that checks a score of 55 is grade D | ||
| */ | ||
|
|
||
| test("a score of 55 is grade D", () => { | ||
| expect(convertScoreToGrade(55)).toEqual("D"); | ||
| }); | ||
| /* | ||
| Write a test that checks a score of 49 is grade E | ||
| */ | ||
|
|
||
| test("a score of 49 is grade E", () => { | ||
| expect(convertScoreToGrade(49)).toEqual("E"); | ||
| }); | ||
| /* | ||
| Write a test that checks a score of 30 is grade E | ||
| */ | ||
|
|
||
| test("a score of 30 is grade E", () => { | ||
| expect(convertScoreToGrade(30)).toEqual("E"); | ||
| }); | ||
|
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. your tests look good! Nice job
Author
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. Yes! We can solve this using If/else statements, using an array to a function that converts score to grade, or using switch. |
||
| /* | ||
| Write a test that checks a score of 70 is grade B | ||
| */ | ||
| test("a score of 70 is grade B", () => { | ||
| expect(convertScoreToGrade(70)).toEqual("B"); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,13 +48,14 @@ function formatCourseworkResult(trainee) { | |
| - (Reminder: You must have run `npm install` one time before this will work!) | ||
| */ | ||
|
|
||
| /* | ||
| Write a test that checks the output of formatCourseworkResult when passed the following trainee: | ||
| { | ||
|
|
||
| // Write a test that checks the output of formatCourseworkResult when passed the following trainee: | ||
| test("trainee has a score of 63", () => {}) | ||
| const trainee = { | ||
| name: "Xin", | ||
| score: 63 | ||
| } | ||
| */ | ||
| }; | ||
|
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. Think you are missing a bit with these tests.... Take a look at the expect function :) Also-- I think there are about 4 more tests after this one which should be updated!
Author
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 will look into this. |
||
|
|
||
|
|
||
| /* | ||
| Write a test that checks the output of formatCourseworkResult when passed the following trainee: | ||
|
|
||
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.
good use of dot notation
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.
Thank you :)