diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 46c150e1..4216cc9f 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,36 +1,36 @@ - - -**Volunteers: Are you marking this coursework?** _You can find a guide on how to mark this coursework in `HOW_TO_MARK.md` in the root of this repository_ - -# Your Details - -- Your Name: -- Your City: -- Your Slack Name: - -# Homework Details - -- Module: -- Week: - -# Notes - -- What did you find easy? - -- What did you find hard? - -- What do you still not understand? - -- Any other notes? + + +**Volunteers: Are you marking this coursework?** _You can find a guide on how to mark this coursework in `HOW_TO_MARK.md` in the root of this repository_ + +# Your Details + +- Your Name: +- Your City: +- Your Slack Name: + +# Homework Details + +- Module: +- Week: + +# Notes + +- What did you find easy? + +- What did you find hard? + +- What do you still not understand? + +- Any other notes? diff --git a/.github/workflows/close.yml b/.github/workflows/close.yml index 137dc57e..59f4d14d 100644 --- a/.github/workflows/close.yml +++ b/.github/workflows/close.yml @@ -1,17 +1,17 @@ -name: "Close stale issues and PRs" -on: - workflow_dispatch: - schedule: - - cron: "30 1 * * *" - -jobs: - stale: - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v3 - with: - stale-pr-message: "Your coursework submission has been closed because nobody has interacted with it in six weeks. You are welcome to re-open it to get more feedback." - days-before-stale: 42 - days-before-close: 0 - days-before-issue-stale: -1 - days-before-issue-close: -1 +name: "Close stale issues and PRs" +on: + workflow_dispatch: + schedule: + - cron: "30 1 * * *" + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v3 + with: + stale-pr-message: "Your coursework submission has been closed because nobody has interacted with it in six weeks. You are welcome to re-open it to get more feedback." + days-before-stale: 42 + days-before-close: 0 + days-before-issue-stale: -1 + days-before-issue-close: -1 diff --git a/.github/workflows/extra-tests.yml b/.github/workflows/extra-tests.yml index 4b75f3cd..69ba56e5 100644 --- a/.github/workflows/extra-tests.yml +++ b/.github/workflows/extra-tests.yml @@ -1,14 +1,14 @@ -name: Run extra tests -on: - pull_request: - paths: - - 3-extra/** -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install modules - run: npm install - - name: Run extra tests - run: npm run extra-tests +name: Run extra tests +on: + pull_request: + paths: + - 3-extra/** +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install modules + run: npm install + - name: Run extra tests + run: npm run extra-tests diff --git a/.github/workflows/mandatory-tests.yml b/.github/workflows/mandatory-tests.yml index 0f87ba09..12d4573c 100644 --- a/.github/workflows/mandatory-tests.yml +++ b/.github/workflows/mandatory-tests.yml @@ -1,11 +1,11 @@ -name: Run mandatory tests -on: pull_request -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install modules - run: npm install - - name: Run mandatory tests - run: npm test +name: Run mandatory tests +on: pull_request +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install modules + run: npm install + - name: Run mandatory tests + run: npm test diff --git a/.gitignore b/.gitignore index 3797f7c4..dabace79 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -node_modules -.DS_Store -package-lock.json +node_modules +.DS_Store +package-lock.json .prettierrc \ No newline at end of file diff --git a/.prettierrc b/.prettierrc index 59bb3b44..b0985c10 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,19 +1,19 @@ -{ - "arrowParens": "always", - "bracketSpacing": true, - "embeddedLanguageFormatting": "auto", - "htmlWhitespaceSensitivity": "css", - "insertPragma": false, - "jsxBracketSameLine": false, - "jsxSingleQuote": false, - "printWidth": 80, - "proseWrap": "preserve", - "quoteProps": "as-needed", - "requirePragma": false, - "semi": true, - "singleQuote": false, - "tabWidth": 2, - "trailingComma": "es5", - "useTabs": false, - "vueIndentScriptAndStyle": false -} +{ + "arrowParens": "always", + "bracketSpacing": true, + "embeddedLanguageFormatting": "auto", + "htmlWhitespaceSensitivity": "css", + "insertPragma": false, + "jsxBracketSameLine": false, + "jsxSingleQuote": false, + "printWidth": 80, + "proseWrap": "preserve", + "quoteProps": "as-needed", + "requirePragma": false, + "semi": true, + "singleQuote": false, + "tabWidth": 2, + "trailingComma": "es5", + "useTabs": false, + "vueIndentScriptAndStyle": false +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..018345da --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "jira-plugin.workingProject": "" +} \ No newline at end of file diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..049fae0b 100644 --- a/1-exercises/A-accessing-values/exercise1.js +++ b/1-exercises/A-accessing-values/exercise1.js @@ -1,28 +1,28 @@ -/* - This object has 4 properties - The properties of the object are all primitive types (string, number or boolean) - What is the type of each property? -*/ - -let dog = { - breed: "Dalmatian", - name: "Spot", - isHungry: true, - happiness: 6 -}; - -/* - You can access the values of each property using dot notation. - Log the name and breed of this dog using dot notation. -*/ - -let dogName; // complete the code -let dogBreed; // complete the code - -console.log(`${dogName} is a ${dogBreed}`); - -/* EXPECTED RESULT - - Spot is a Dalmatian - +/* + This object has 4 properties + The properties of the object are all primitive types (string, number or boolean) + What is the type of each property? +*/ + +let dog = { + breed: "Dalmatian", + name: "Spot", + isHungry: true, + happiness: 6 +}; + +/* + You can access the values of each property using dot notation. + Log the name and breed of this dog using dot notation. +*/ + +let dogName = dog.name; // complete the code +let dogBreed = dog.breed; // complete the code + +console.log(`${dogName} is a ${dogBreed}`); + +/* EXPECTED RESULT + + Spot is a Dalmatian + */ \ No newline at end of file diff --git a/1-exercises/A-accessing-values/exercise2.js b/1-exercises/A-accessing-values/exercise2.js index 5b523ace..3c40c961 100644 --- a/1-exercises/A-accessing-values/exercise2.js +++ b/1-exercises/A-accessing-values/exercise2.js @@ -1,28 +1,28 @@ -/* - You can also access the value of a property using bracket notation. - Bracket notation can be used when the property is stored as the value of a variable. - This can be very useful for iterating through an object's properties or when accessing a lookup table. -*/ - -let capitalCities = { - UnitedKingdom: "London", - China: "Beijing", - Peru: "Lima" -}; - -/* - You have an object, capitalCities, that contains key/value pairs of countries and their capital cities. - Log the value for the property assigned to the variable myCountry using bracket notation. - Do not use dot notation for this exercise! -*/ - -let myCountry = "UnitedKingdom"; -let myCapitalCity; // complete the code - -console.log(myCapitalCity); - -/* EXPECTED RESULT - - London - +/* + You can also access the value of a property using bracket notation. + Bracket notation can be used when the property is stored as the value of a variable. + This can be very useful for iterating through an object's properties or when accessing a lookup table. +*/ + +let capitalCities = { + UnitedKingdom: "London", + China: "Beijing", + Peru: "Lima" +}; + +/* + You have an object, capitalCities, that contains key/value pairs of countries and their capital cities. + Log the value for the property assigned to the variable myCountry using bracket notation. + Do not use dot notation for this exercise! +*/ + +let myCountry = "UnitedKingdom"; +let myCapitalCity = capitalCities[myCountry]; // complete the code + +console.log(myCapitalCity); + +/* EXPECTED RESULT + + London + */ \ No newline at end of file diff --git a/1-exercises/A-accessing-values/exercise3.js b/1-exercises/A-accessing-values/exercise3.js index 2e160dd5..4e8639da 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -1,32 +1,35 @@ -/* - An object's properties can have values that are other objects or arrays. -*/ - -let basketballTeam = { - name: "Chicago Bulls", - numberOfPlayers: 15, - topPlayers: ["Michael Jordan", "Scottie Pippen", "Dennis Rodman"], - homeStadium: { - name: "United Center", - capacity: 21000, - address: "1901 W Madison St", - }, -}; - -/* - Write code that - - accesses the basketball team's top players array - - sorts the top players in alphabetical order - - console.logs the name of each player on a new line -*/ - -// write code here - - -/* EXPECTED RESULT - - Dennis Rodman - Michael Jordan - Scottie Pippen - +/* + An object's properties can have values that are other objects or arrays. +*/ + +let basketballTeam = { + name: "Chicago Bulls", + numberOfPlayers: 15, + topPlayers: ["Michael Jordan", "Scottie Pippen", "Dennis Rodman"], + homeStadium: { + name: "United Center", + capacity: 21000, + address: "1901 W Madison St", + }, +}; + +/* + Write code that + - accesses the basketball team's top players array + - sorts the top players in alphabetical order + - console.logs the name of each player on a new line +*/ +let topPlayers = basketballTeam.topPlayers.sort(); +// console.log(topPlayers) +for (let players of topPlayers) { + console.log(players); +};// write code here + + +/* EXPECTED RESULT + + Dennis Rodman + Michael Jordan + Scottie Pippen + */ \ No newline at end of file diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..93c64fbf 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -1,37 +1,44 @@ -/* - You can add properties to objects and assign values to them using dot notation. - You can also change the value assigned to a property using dot notation. -*/ - -let capitalCities = { - UnitedKingdom: { - name: "London", - population: 20, - }, - China: { - name: "Beijing", - } -}; - -/* - Using dot notation: - - Change the value of UnitedKingdom's capital city population to 8980000. - - Add the property for population to China's capital city and set the value to 21500000. - - Add the country "Peru" to capitalCities object. - - Add a name of "Lima" to Peru's capital city. - - Add a population of 9750000 to Peru's capital city. -*/ - -// write code here - -console.log(capitalCities); - -/* EXPECTED RESULT - - { - UnitedKingdom: { name: "London", population: 8980000 }, - China: { name: "Beijing", population: 21500000 }, - Peru: { name: "Lima", population: 9750000 } - } - +/* + You can add properties to objects and assign values to them using dot notation. + You can also change the value assigned to a property using dot notation. +*/ + +let capitalCities = { + UnitedKingdom: { + name: "London", + population: 20, + }, + China: { + name: "Beijing", + } +}; + +/* + Using dot notation: + - Change the value of UnitedKingdom's capital city population to 8980000. + - Add the property for population to China's capital city and set the value to 21500000. + - Add the country "Peru" to capitalCities object. + - Add a name of "Lima" to Peru's capital city. + - Add a population of 9750000 to Peru's capital city. +*/ + +capitalCities.UnitedKingdom.population = 8980000; +capitalCities.China.population = 21500000; + + +capitalCities.Peru = {name: "Lima", population: 9750000}; +// capitalCities.Peru['name'] = "Lima"; +// capitalCities.Peru['population'] = 9750000; +// capitalCities.Peru.population = 9750000;// write code here + +console.log(capitalCities); + +/* EXPECTED RESULT + + { + UnitedKingdom: { name: "London", population: 8980000 }, + China: { name: "Beijing", population: 21500000 }, + Peru: { name: "Lima", population: 9750000 } + } + */ \ No newline at end of file diff --git a/1-exercises/B-setting-values/exercise2.js b/1-exercises/B-setting-values/exercise2.js index 59fb7c1e..cf34cbe2 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -1,41 +1,44 @@ -/* - You can add properties to objects and assign values to them using bracket notation. - You can also change the value assigned to a property using bracket notation. -*/ - -let student = { - name: "Reshma Saujani", - examScore: 65, - hasPassed: false -}; - -/* - Using bracket notation - - Add a property to the student object for attendance - - Set the value of attendance to 90 -*/ - -// write code here - -/* - - Write an "if" statement that changes the value of hasPassed to true - if the student has attendance that is equal or greater than 90 - AND - exam score is above 60. - - Use bracket notation to change the value of hasPassed -*/ - -// write code here - -console.log(student); - -/* EXPECTED RESULT - - { - name: "Reshma Saujani", - examScore: 65, - hasPassed: true, - attendance: 90 - } - +/* + You can add properties to objects and assign values to them using bracket notation. + You can also change the value assigned to a property using bracket notation. +*/ + +let student = { + name: "Reshma Saujani", + examScore: 65, + hasPassed: false +}; + +/* + Using bracket notation + - Add a property to the student object for attendance + - Set the value of attendance to 90 +*/ + +student['attendance'] = 90; +if (student.attendance >= 90) { + student.hasPassed = true; +} // write code here + +/* + - Write an "if" statement that changes the value of hasPassed to true + if the student has attendance that is equal or greater than 90 + AND + exam score is above 60. + - Use bracket notation to change the value of hasPassed +*/ + +// write code here + +console.log(student); + +/* EXPECTED RESULT + + { + name: "Reshma Saujani", + examScore: 65, + hasPassed: true, + attendance: 90 + } + */ \ No newline at end of file diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..d13b86ee 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -1,38 +1,37 @@ -/* - You have already seen "undefined", either in an error message or being output from your program. - - As a reminder, in some cases, undefined will be used by a programmer intentionally, and they will write code to handle it. - But usually, when you see undefined - it means something has gone wrong! - - Below are some examples of when you would see undefined when using objects. - For each example, can you explain why we are seeing undefined? -*/ - -// Example 1 -let car = { - brand: "Ford", - yearsOld: 8, -}; - -console.log(car["colour"]); - -// Example 2 -function sayHelloToUser(user) { - console.log(`Hello ${user.firstName}`); -} - -let user = { - name: "Mira" -}; - -sayHelloToUser(user); - -// Example 3 -let myPet = { - animal: "Cat", - getName: function() { - "My pet's name is Fluffy"; - }, -}; - -console.log(myPet.getName()); +/* + You have already seen "undefined", either in an error message or being output from your program. + + As a reminder, in some cases, undefined will be used by a programmer intentionally, and they will write code to handle it. + But usually, when you see undefined - it means something has gone wrong! + + Below are some examples of when you would see undefined when using objects. + For each example, can you explain why we are seeing undefined? +*/ + +// Example 1 +let car = { + brand: "Ford", + yearsOld: 8, +}; +console.log(car["colour"]); +// there is no colour property being declare + +// Example 2 +function sayHelloToUser(user) { + console.log(`Hello ${user.firstName}`); +} +let user = { + name: "Mira" +}; +sayHelloToUser(user); +// there is no property with firstName, only name + +// Example 3 +let myPet = { + animal: "Cat", + getName: function() { + "My pet's name is Fluffy"; + }, +}; +console.log(myPet.getName()); +// function is not complete, getName is not declared diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..334a2bdd 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -1,20 +1,26 @@ -/* - The values assigned to object properties can also be functions. - When a function belongs to an object it is called a method. - - Add a method called getName to the students object that - - takes an argument called name which is a string - - console.logs a message that says: "Student name: " followed by the name given as an argument -*/ - -let student = { - // write code here -} - -student.getName("Daniel"); - -/* EXPECTED RESULT - - Student name: Daniel - +/* + The values assigned to object properties can also be functions. + When a function belongs to an object it is called a method. + + Add a method called getName to the students object that + - takes an argument called name which is a string + - console.logs a message that says: "Student name: " followed by the name given as an argument +*/ + +let student = { + name: "Daniel", + getName: function () { + getName = student.name; + console.log("Student name: " + getName); + } + // console.console.log(`Student name: ${this.getName}`); + // write code here +} + +student.getName("Daniel"); + +/* EXPECTED RESULT + + Student name: Daniel + */ \ No newline at end of file diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..978a0093 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -1,25 +1,91 @@ -/* - The Recipe Card - Never forget another recipe! - - Create an object to hold information on your favorite recipe. - - It should have properties for - - - title (a string), - - servings (a number), and - - ingredients (an array of strings) - - On separate lines (one console.log statement for each), log the recipe information so it looks like: - - Mole - Serves: 2 - Ingredients: - cinnamon - cumin - cocoa - - You should write and log at least 5 recipes -*/ - +/* + The Recipe Card + Never forget another recipe! + + Create an object to hold information on your favorite recipe. + + It should have properties for + + - title (a string), + - servings (a number), and + - ingredients (an array of strings) + + On separate lines (one console.log statement for each), log the recipe information so it looks like: + + Mole + Serves: 2 + Ingredients: + cinnamon + cumin + cocoa + + You should write and log at least 5 recipes +*/ +let recipeFavs = { + + pizza:{ + title: "Hawaian", + servings: 1, + ingredients: ["base", "pineapple", "cheese", "green peppers", "tomatoes"], + }, + + kentucky: { + title: "Streetwise2", + servings: 2, + ingredients: ["chicken", "chips"], + }, + + steers: { + title: "Wacky Wednesday", + servings: 4, + ingredients: ["burger rolls", "burger patty", "onions", "tomato", "lettuce", "sauce"], + }, + + gatspy: { + title: "Rootie Gatspy", + servings: 1, + ingredients: ["rootie", "chips", "steak", "salads"], + }, + + wimpyBreakfeast: { + title: "Good morning breakfeast", + servings: 2, + ingredients: ["eggs", "bangers", "bread", "bacon"], + }, + } + + console.log(recipeFavs.pizza.title); + console.log(`servings: ${recipeFavs.pizza.servings}`); + console.log('ingredients: ') + recipeFavs.pizza.ingredients.forEach((ingredient) => { + console.log(ingredient) + }); + + console.log(recipeFavs.kentucky.title); + console.log(`servings: ${recipeFavs.kentucky.servings}`); + console.log('ingredients: ') + recipeFavs.kentucky.ingredients.forEach((ingredient) => { + console.log(ingredient) + }); + + console.log(recipeFavs.steers.title); + console.log(`servings: ${recipeFavs.steers.servings}`); + console.log('ingredients: ') + recipeFavs.steers.ingredients.forEach((ingredient) => { + console.log(ingredient) + }); + + console.log(recipeFavs.gatspy.title); + console.log(`servings: ${recipeFavs.gatspy.servings}`); + console.log('ingredients: ') + recipeFavs.gatspy.ingredients.forEach((ingredient) => { + console.log(ingredient) + }); + + console.log(recipeFavs.wimpyBreakfeast.title); + console.log(`servings: ${recipeFavs.wimpyBreakfeast.servings}`); + console.log('ingredients: ') + recipeFavs.wimpyBreakfeast.ingredients.forEach((ingredient) => { + console.log(ingredient) + }); // write code here \ No newline at end of file diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..e45e6478 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -1,37 +1,55 @@ -/* - Objects can be thought of as key/value storage, like a dictionary or a 'lookup'. - - You have a variable called COUNTRY_CURRENCY_CODES which is an array of arrays. - Each inner array contains a country code and its currency code. - - Write a function called createLookup that - - takes COUNTRY_CURRENCY_CODES as an argument (remember, it's an array of arrays) - - returns a new object where the keys are the country codes and the values are the currency codes - Hint: you'll need to use bracket notation to add new key/value pairs to the object -*/ - -const COUNTRY_CURRENCY_CODES = [ - ["GB", "GBP"], - ["DE", "EUR"], - ["NG", "NGN"], - ["MX", "MXN"], -]; - -function createLookup(countryCurrencyCodes) { - // write code here -} - -/* ======= TESTS - DO NOT MODIFY ===== -- To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js` -- To run all exercises/tests in the mandatory folder, run `npm test` -- (Reminder: You must have run `npm install` one time before this will work!) -*/ - -test("creates country currency code lookup", () => { - expect(createLookup(COUNTRY_CURRENCY_CODES)).toEqual({ - GB: "GBP", - DE: "EUR", - NG: "NGN", - MX: "MXN", - }); +/* + Objects can be thought of as key/value storage, like a dictionary or a 'lookup'. + + You have a variable called COUNTRY_CURRENCY_CODES which is an array of arrays. + Each inner array contains a country code and its currency code. + + Write a function called createLookup that + - takes COUNTRY_CURRENCY_CODES as an argument (remember, it's an array of arrays) + - returns a new object where the keys are the country codes and the values are the currency codes + Hint: you'll need to use bracket notation to add new key/value pairs to the object +*/ + +const COUNTRY_CURRENCY_CODES = [ + ["GB", "GBP"], + ["DE", "EUR"], + ["NG", "NGN"], + ["MX", "MXN"], +]; + +function createLookup(countryCurrencyCodes) { + let newObject = {}; + for (let index of countryCurrencyCodes) { + newObject[index[0]] = index[1]; + } + return newObject; + // return countryCurrencyCodes.slice((0, 2)); + // function createLookup(countryCurrencyCodes) { + // let COUNTRY_CURRENCY_CODES = countryCurrencyCodes; + // let result = []; + // while (countryCurrencyCodes == COUNTRY_CURRENCY_CODES) { + // result = countryCurrencyCodes.index[0, "1"]; + // countryCurrencyCodes = Object.getPrototypeOf(countryCurrencyCodes); + // result = countryCurrencyCodes.index[ `${index(0), index("1")}`]; + // result = countryCurrencyCodes.index[{COUNTRY_CURRENCY_CODES.index(0) : index("1")}]; + // result = countryCurrencyCodes.index[0, 1, 2 ,3 [1, 0]]; + // } + // return result; + // must come back + // write code here +} + +/* ======= TESTS - DO NOT MODIFY ===== +- To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js` +- To run all exercises/tests in the mandatory folder, run `npm test` +- (Reminder: You must have run `npm install` one time before this will work!) +*/ + +test("creates country currency code lookup", () => { + expect(createLookup(COUNTRY_CURRENCY_CODES)).toEqual({ + GB: "GBP", + DE: "EUR", + NG: "NGN", + MX: "MXN", + }); }); \ No newline at end of file diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..e4cd5b21 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -1,53 +1,75 @@ -/* - You have a pantry object that tells you the contents of your fridge and your cupboards. - - Write a function createShoppingList that takes a recipe as a parameter. - The recipe parameter has two properties: - - "name", which is a string - - "ingredients", which is an array of strings - - The createShoppingList function should find which ingredients from the recipe are missing from the pantry. - - The createShoppingList function should return an object with two properties: - - "name" of the recipe, which is a string, - - "items", which is an arry of the missing ingredients that need to be on the shopping list -*/ - -let pantry = { - fridgeContents: ["butter", "milk"], - cupboardContents: ["salt", "tinned tomatoes", "oregano"], -}; - -function createShoppingList(recipe) { - // write code here -} - -/* ======= TESTS - DO NOT MODIFY ===== -- To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js` -- To run all exercises/tests in the mandatory folder, run `npm test` -- (Reminder: You must have run `npm install` one time before this will work!) -*/ - -test("createShoppingList works for pancakes recipe", () => { - let recipe1 = { - name: "pancakes", - ingredients: ["flour", "salt", "milk", "eggs", "vegetable oil"], - }; - - expect(createShoppingList(recipe1)).toEqual({ - name: "pancakes", - items: ["flour", "eggs", "vegetable oil"], - }); -}); - -test("createShoppingList works for margherita pizza recipe", () => { - let recipe2 = { - name: "margherita pizza", - ingredients: ["flour", "salt", "yeast", "tinned tomatoes", "oregano", "mozarella"], - }; - - expect(createShoppingList(recipe2)).toEqual({ - name: "margherita pizza", - items: ["flour", "yeast", "mozarella"] - }); +/* + You have a pantry object that tells you the contents of your fridge and your cupboards. + + Write a function createShoppingList that takes a recipe as a parameter. + The recipe parameter has two properties: + - "name", which is a string + - "ingredients", which is an array of strings + + The createShoppingList function should find which ingredients from the recipe are missing from the pantry. + + The createShoppingList function should return an object with two properties: + - "name" of the recipe, which is a string, + - "items", which is an arry of the missing ingredients that need to be on the shopping list +*/ + +let pantry = { + fridgeContents: ["butter", "milk"], + cupboardContents: ["salt", "tinned tomatoes", "oregano"], +}; + +// function createShoppingList("name", [ingredients]) { +// if (ingredients !== Object.value(pantry.cupboardContents)) +// return `${"name"} ${Object.}` + + +function createShoppingList(recipe) { + let ingredientsShort = [`${pantry.fridgeContents.join(", ")}, ` + `${pantry.cupboardContents.join(", ")}`]; + if (ingredientsShort.includes(recipe.ingredients) === false) { + + return `{items: [${ingredientsShort}], name: ${recipe.name}}`; + } + + // function createShoppingList(recipe) { + // if (ingredientsShort = recipe.ingredients.filter((fridgeContents, cupboardContents) => { + // recipe.ingredients.includes(fridgeContents && cupboardContents))) { + // return ingredientsShort; + // }} + // if (ingredientsShort = recipe.ingredients.filter(cupboardContents => recipe.ingredients.includes(cupboardContents))) { + // return ingredientsShort; + // } +} + + // write code here + + +/* ======= TESTS - DO NOT MODIFY ===== +- To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js` +- To run all exercises/tests in the mandatory folder, run `npm test` +- (Reminder: You must have run `npm install` one time before this will work!) +*/ + +test("createShoppingList works for pancakes recipe", () => { + let recipe1 = { + name: "pancakes", + ingredients: ["flour", "salt", "milk", "eggs", "vegetable oil"], + }; + + expect(createShoppingList(recipe1)).toEqual({ + name: "pancakes", + items: ["flour", "eggs", "vegetable oil"], + }); +}); + +test("createShoppingList works for margherita pizza recipe", () => { + let recipe2 = { + name: "margherita pizza", + ingredients: ["flour", "salt", "yeast", "tinned tomatoes", "oregano", "mozarella"], + }; + + expect(createShoppingList(recipe2)).toEqual({ + + name: "margherita pizza", + items: ["flour", "yeast", "mozarella"] + }); }); \ No newline at end of file diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..a7e419d3 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -1,50 +1,62 @@ -/* - You are at a restaurant that has two items on the menu, burger and falafel. - The menu object includes these two items and their price. - - You have an object cashRegister which handles charging for ordered items but it is missing some methods to do this. - - Add a method to the cashRegister object - - the method name should be orderBurger - - the method should take one argument called balance, which is a number - - the method should check if there is enough money in the balance to order a burger (i.e. will the balance be greater than or equal to 0 if the burger is ordered) - - if there is enough money in the balance to order the burger, then the price of the burger should be subtracted from the balance - - the method should return the new balance - - Add another method to the cashRegister object which is called orderFalafel and handles ordering a falafel, in the same way as ordering a burger. -*/ - -const MENU = { - burger: 6.5, - falafel: 7.25, -}; - -let cashRegister = { - // write code here -} - -/* ======= TESTS - DO NOT MODIFY ===== -- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js` -- To run all exercises/tests in the mandatory folder, run `npm test` -- (Reminder: You must have run `npm install` one time before this will work!) -*/ - -test("orderBurger subtracts 6.5 from balance", () => { - let balance = 6.5; - expect(cashRegister.orderBurger(balance)).toEqual(0); -}); - -test("orderFalafel subtracts 7.25 from balance", () => { - let balance = 7.25; - expect(cashRegister.orderFalafel(balance)).toEqual(0); -}); - -test("orderBurger will not subtract from balance if balance is too low", () => { - let balance = 6.49; - expect(cashRegister.orderBurger(balance)).toEqual(6.49); -}); - -test("orderFalafel will not subtract from balance if balance is too low", () => { - let balance = 7.24; - expect(cashRegister.orderFalafel(balance)).toEqual(7.24); -}); +/* + You are at a restaurant that has two items on the menu, burger and falafel. + The menu object includes these two items and their price. + + You have an object cashRegister which handles charging for ordered items but it is missing some methods to do this. + + Add a method to the cashRegister object + - the method name should be orderBurger + - the method should take one argument called balance, which is a number + - the method should check if there is enough money in the balance to order a burger (i.e. will the balance be greater than or equal to 0 if the burger is ordered) + - if there is enough money in the balance to order the burger, then the price of the burger should be subtracted from the balance + - the method should return the new balance + + Add another method to the cashRegister object which is called orderFalafel and handles ordering a falafel, in the same way as ordering a burger. +*/ + +const MENU = { + burger: 6.5, + falafel: 7.25, +}; + +let cashRegister = { + orderBurger: function() { + if (balance <= burger) { + let newBalance = balance - burger; + return newBalance; + } + } + orderFalafel: function() { + if (balance <= falafel) { + let newBalance = balance - falafel; + return newBalance; + } + } + // write code here +} + +/* ======= TESTS - DO NOT MODIFY ===== +- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js` +- To run all exercises/tests in the mandatory folder, run `npm test` +- (Reminder: You must have run `npm install` one time before this will work!) +*/ + +test("orderBurger subtracts 6.5 from balance", () => { + let balance = 6.5; + expect(cashRegister.orderBurger(balance)).toEqual(0); +}); + +test("orderFalafel subtracts 7.25 from balance", () => { + let balance = 7.25; + expect(cashRegister.orderFalafel(balance)).toEqual(0); +}); + +test("orderBurger will not subtract from balance if balance is too low", () => { + let balance = 6.49; + expect(cashRegister.orderBurger(balance)).toEqual(6.49); +}); + +test("orderFalafel will not subtract from balance if balance is too low", () => { + let balance = 7.24; + expect(cashRegister.orderFalafel(balance)).toEqual(7.24); +}); diff --git a/3-extra/1-count-words.js b/3-extra/1-count-words.js index 9d347ae5..4f5df957 100644 --- a/3-extra/1-count-words.js +++ b/3-extra/1-count-words.js @@ -1,71 +1,71 @@ -/* - This exercise is to write function that counts the number of times each word appears in a string. - - Write a function called countWords that - - takes a string as an argument - - returns an object where - - the keys are the words from the string and - - the values are the number of times the word appears in the string - - Example - If the function is given the input: - - "you and me and you"; - - the object returned would be: - - { you: 2, and: 2, me: 1 } - - To complete this exercise you should understand - - Strings and string manipulation - - Loops or forEach - - Comparison inside if statements - - Setting values on an object -*/ - -function countWords(string) { - const wordCount = {}; - - // write code here - - return wordCount; -} - -/* ======= TESTS - DO NOT MODIFY ===== -- To run the tests for this exercise, run `npm run extra-tests` -- To run all exercises/tests in the mandatory folder, run `npm test` -- (Reminder: You must have run `npm install` one time before this will work!) -*/ - -test("Code works for a small string", () => { - expect(countWords("I love CodeYourFuture")).toEqual({ - I: 1, - love: 1, - CodeYourFuture: 1, - }); -}); - -test("A string with, some punctuation", () => { - expect(countWords("A string with, some punctuation")).toEqual( - { A: 1, string: 1, "with,": 1, some: 1, punctuation: 1 } - ); -}); - -test("Empty string", () => { - expect(countWords("")).toEqual({}); -}); - -test("Example task string", () => { - expect(countWords("you're braver than you believe, stronger than you seem, and smarter than you think")).toEqual({ - "you're": 1, - and: 1, - "believe,": 1, - braver: 1, - "seem,": 1, - smarter: 1, - stronger: 1, - than: 3, - think: 1, - you: 3, - }); -}); +/* + This exercise is to write function that counts the number of times each word appears in a string. + + Write a function called countWords that + - takes a string as an argument + - returns an object where + - the keys are the words from the string and + - the values are the number of times the word appears in the string + + Example + If the function is given the input: + + "you and me and you"; + + the object returned would be: + + { you: 2, and: 2, me: 1 } + + To complete this exercise you should understand + - Strings and string manipulation + - Loops or forEach + - Comparison inside if statements + - Setting values on an object +*/ + +function countWords(string) { + const wordCount = {}; + + // write code here + + return wordCount; +} + +/* ======= TESTS - DO NOT MODIFY ===== +- To run the tests for this exercise, run `npm run extra-tests` +- To run all exercises/tests in the mandatory folder, run `npm test` +- (Reminder: You must have run `npm install` one time before this will work!) +*/ + +test("Code works for a small string", () => { + expect(countWords("I love CodeYourFuture")).toEqual({ + I: 1, + love: 1, + CodeYourFuture: 1, + }); +}); + +test("A string with, some punctuation", () => { + expect(countWords("A string with, some punctuation")).toEqual( + { A: 1, string: 1, "with,": 1, some: 1, punctuation: 1 } + ); +}); + +test("Empty string", () => { + expect(countWords("")).toEqual({}); +}); + +test("Example task string", () => { + expect(countWords("you're braver than you believe, stronger than you seem, and smarter than you think")).toEqual({ + "you're": 1, + and: 1, + "believe,": 1, + braver: 1, + "seem,": 1, + smarter: 1, + stronger: 1, + than: 3, + think: 1, + you: 3, + }); +}); diff --git a/GRADING.md b/GRADING.md index e5859d20..7444aada 100644 --- a/GRADING.md +++ b/GRADING.md @@ -1,20 +1,20 @@ - - -# Grading - -All coursework is graded using the Marking Guide found on the Syllabus. - -http://syllabus.codeyourfuture.io/guides/marking-guide - -If you have any questions on these guidelines - please ask. - -## Coding Standards - -Your code should follow our Coding Standards or it will be marked poorly. - -https://syllabus.codeyourfuture.io/guides/code-style-guide + + +# Grading + +All coursework is graded using the Marking Guide found on the Syllabus. + +http://syllabus.codeyourfuture.io/guides/marking-guide + +If you have any questions on these guidelines - please ask. + +## Coding Standards + +Your code should follow our Coding Standards or it will be marked poorly. + +https://syllabus.codeyourfuture.io/guides/code-style-guide diff --git a/HOW-TO-GET-HELP.md b/HOW-TO-GET-HELP.md index e4db1b56..7de658b3 100644 --- a/HOW-TO-GET-HELP.md +++ b/HOW-TO-GET-HELP.md @@ -1,38 +1,38 @@ - - -# How To Get Help - -When you get stuck it's important that you ask for help at the right time and in the right way - this means you will be able to solve you problem as quickly as possible! - -## Guide - -Please review our guide on the Syllabus for how to get help - -https://syllabus.codeyourfuture.io/guides/escalation-policy/ - -You should complete all of the steps in the order listed to get help - -## Reporting Issues in Coursework - -Is there a problem with this coursework? -Have you noticed a bug? -Does something not make sense? - -Post in the channel named after the module you are working on: - -- Git - `cyf-module-git` -- HTML/CSS - `cyf-module-html-css` -- JavaScript Core 1 - `cyf-module-js1` -- JavaScript Core 2 - `cyf-module-js2` -- JavaScript Core 2 - `cyf-module-js3` -- React - `cyf-module-react` -- Node - `cyf-module-node` -- SQL - `cyf-module-sql` -- MongoDB - `cyf-module-mongodb` - -None of these? Post in #cyf-syllabus. + + +# How To Get Help + +When you get stuck it's important that you ask for help at the right time and in the right way - this means you will be able to solve you problem as quickly as possible! + +## Guide + +Please review our guide on the Syllabus for how to get help + +https://syllabus.codeyourfuture.io/guides/escalation-policy/ + +You should complete all of the steps in the order listed to get help + +## Reporting Issues in Coursework + +Is there a problem with this coursework? +Have you noticed a bug? +Does something not make sense? + +Post in the channel named after the module you are working on: + +- Git - `cyf-module-git` +- HTML/CSS - `cyf-module-html-css` +- JavaScript Core 1 - `cyf-module-js1` +- JavaScript Core 2 - `cyf-module-js2` +- JavaScript Core 2 - `cyf-module-js3` +- React - `cyf-module-react` +- Node - `cyf-module-node` +- SQL - `cyf-module-sql` +- MongoDB - `cyf-module-mongodb` + +None of these? Post in #cyf-syllabus. diff --git a/HOW-TO-SUBMIT.md b/HOW-TO-SUBMIT.md index e6c8a6f0..7dec4288 100644 --- a/HOW-TO-SUBMIT.md +++ b/HOW-TO-SUBMIT.md @@ -1,24 +1,24 @@ - - -# How To Submit Your Coursework - -Use Git & Github to submit your coursework as a pull request. - -The Github Desktop cheatsheet will help you. - -[Github Desktop Cheatsheet](http://syllabus.codeyourfuture.io/git/cheatsheet) - -This lesson will help you submit your coursework. - -[Git Lesson](http://syllabus.codeyourfuture.io/git/index) - -## Questions & Help - -Not being able to submit your coursework is not an excuse for not doing it. - -If you cannot submit your coursework you **must** message us on Slack to get help. + + +# How To Submit Your Coursework + +Use Git & Github to submit your coursework as a pull request. + +The Github Desktop cheatsheet will help you. + +[Github Desktop Cheatsheet](http://syllabus.codeyourfuture.io/git/cheatsheet) + +This lesson will help you submit your coursework. + +[Git Lesson](http://syllabus.codeyourfuture.io/git/index) + +## Questions & Help + +Not being able to submit your coursework is not an excuse for not doing it. + +If you cannot submit your coursework you **must** message us on Slack to get help. diff --git a/HOW_TO_MARK.md b/HOW_TO_MARK.md index a2865714..28a635b4 100644 --- a/HOW_TO_MARK.md +++ b/HOW_TO_MARK.md @@ -1,63 +1,63 @@ - - -_This file is useful for Volunteers only_ - -## 1) Solutions - -### 1.1) Where to find solutions? - -Add `-Solution` to the end of a repo url to find the solution. - -For this repo: - -https://github.com/CodeYourFuture/JavaScript-Core-2-Coursework-Week1-London8 - -Find the solution here: - -https://github.com/CodeYourFuture/JavaScript-Core-2-Coursework-Week1-London8-Solution - -**If you do not have access to these repositories** Contact your City Coordinator to get access to our Github Team. - -### 1.2) Using the Solutions Repo - -These solutions are example answers not the only correct answers. Use them to inform your feedback on the coursework. - -Look for marking guides in these places: - -- The `marking` folder - Used to store multiple guides on marking -- `marking.md` file - Used to store notes on common problems we're trying to address -- `solutions.md` - A file used by students for notes on best practice - -## 2) Before You Start - -### 2.1) Feedback Guide - -Please read this guide before you start marking. - -https://docs.codeyourfuture.io/teams/education/homework-feedback - -### 2.2) Marking Guide - -When you see trainees make common mistakes, direct them to this marking guide. - -https://syllabus.codeyourfuture.io/guides/marking-guide - -For example, if the student is leaving in lots of commented out code, write a short response like this: - -```txt -Great work so far! - -It's best to remove code that you're not using. Read more about this here: -https://syllabus.codeyourfuture.io/guides/marking-guide#commented-out-code -``` - -### 3.3) Style Guide - -All code at CYF should follow this Style Guide: - -https://syllabus.codeyourfuture.io/guides/code-style-guide/ + + +_This file is useful for Volunteers only_ + +## 1) Solutions + +### 1.1) Where to find solutions? + +Add `-Solution` to the end of a repo url to find the solution. + +For this repo: + +https://github.com/CodeYourFuture/JavaScript-Core-2-Coursework-Week1-London8 + +Find the solution here: + +https://github.com/CodeYourFuture/JavaScript-Core-2-Coursework-Week1-London8-Solution + +**If you do not have access to these repositories** Contact your City Coordinator to get access to our Github Team. + +### 1.2) Using the Solutions Repo + +These solutions are example answers not the only correct answers. Use them to inform your feedback on the coursework. + +Look for marking guides in these places: + +- The `marking` folder - Used to store multiple guides on marking +- `marking.md` file - Used to store notes on common problems we're trying to address +- `solutions.md` - A file used by students for notes on best practice + +## 2) Before You Start + +### 2.1) Feedback Guide + +Please read this guide before you start marking. + +https://docs.codeyourfuture.io/teams/education/homework-feedback + +### 2.2) Marking Guide + +When you see trainees make common mistakes, direct them to this marking guide. + +https://syllabus.codeyourfuture.io/guides/marking-guide + +For example, if the student is leaving in lots of commented out code, write a short response like this: + +```txt +Great work so far! + +It's best to remove code that you're not using. Read more about this here: +https://syllabus.codeyourfuture.io/guides/marking-guide#commented-out-code +``` + +### 3.3) Style Guide + +All code at CYF should follow this Style Guide: + +https://syllabus.codeyourfuture.io/guides/code-style-guide/ diff --git a/README.md b/README.md index 62ea5a71..f3dcba1a 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,29 @@ -Like learning a musical instrument, programming requires daily practise. - -The exercises are split into three folders: `exercises`, `mandatory` and `extra`. All homework in the `exercises` and `mandatory` sections **must** be completed for homework by the following lesson. - -The `extra` folder contains exercises that you can complete to challenge yourself, but are not required for the following lesson. - -## Solutions - -The solutions for this coursework can be found here: - -https://github.com/CodeYourFuture/JavaScript-Core-2-Coursework-Week1-London8-Solution - -This is a **private** repository. Please request access from your Teachers, Buddy or City Coordinator after the start of your next lesson. - -## Testing your work - -- Each of the \*.js files in the `1-exercises` folder can be run from the terminal using the `node` command with the path to the file. For example, `node 1-exercises/A-accessing-values/exercise1.js` can be run from the root of the project. -- To run the tests in the `2-mandatory` folder, run `npm run test` from the root of the project (after having run `npm install` once before). -- To run a single exercise/test (for example `2-mandatory/2-currency-code-lookup.js`), run `npm test -- --testPathPattern 2-mandatory/2-currency-code-lookup.js`. -- The `2-mandatory/1-recipes.js` exercise does not use jest. To run this file individually, use node directly. `node 2-mandatory/1-recipes.js`. -- To run the tests in the `3-extra` folder, run `npm run extra-tests` from the root of the project (after having run `npm install` once before). - -## Instructions for submission - -For your homework, we'll be using [**test driven development**](https://medium.com/@adityaalifnugraha/test-driven-development-tdd-in-a-nutshell-b9e05dfe8adb) to check your answers. Test driven development (or TDD) is the practice of writing tests for your code first, and then write your code to pass those tests. This is a very useful way of writing good quality code and is used in a lot of industries. You don't have to worry about knowing how this works, but if you're curious, engage with a volunteer to find out more! :) - -1. Complete the challenges in each file and save it once you're happy with your changes -2. Run the script to check the results against the tests - all tests should read PASSED if you completed the challenges correctly. If a test reads FAILED, find the associated test to identify which function failed and fix it. -3. Raise a PR once you're happy with the quality of your code +Like learning a musical instrument, programming requires daily practise. + +The exercises are split into three folders: `exercises`, `mandatory` and `extra`. All homework in the `exercises` and `mandatory` sections **must** be completed for homework by the following lesson. + +The `extra` folder contains exercises that you can complete to challenge yourself, but are not required for the following lesson. + +## Solutions + +The solutions for this coursework can be found here: + +https://github.com/CodeYourFuture/JavaScript-Core-2-Coursework-Week1-London8-Solution + +This is a **private** repository. Please request access from your Teachers, Buddy or City Coordinator after the start of your next lesson. + +## Testing your work + +- Each of the \*.js files in the `1-exercises` folder can be run from the terminal using the `node` command with the path to the file. For example, `node 1-exercises/A-accessing-values/exercise1.js` can be run from the root of the project. +- To run the tests in the `2-mandatory` folder, run `npm run test` from the root of the project (after having run `npm install` once before). +- To run a single exercise/test (for example `2-mandatory/2-currency-code-lookup.js`), run `npm test -- --testPathPattern 2-mandatory/2-currency-code-lookup.js`. +- The `2-mandatory/1-recipes.js` exercise does not use jest. To run this file individually, use node directly. `node 2-mandatory/1-recipes.js`. +- To run the tests in the `3-extra` folder, run `npm run extra-tests` from the root of the project (after having run `npm install` once before). + +## Instructions for submission + +For your homework, we'll be using [**test driven development**](https://medium.com/@adityaalifnugraha/test-driven-development-tdd-in-a-nutshell-b9e05dfe8adb) to check your answers. Test driven development (or TDD) is the practice of writing tests for your code first, and then write your code to pass those tests. This is a very useful way of writing good quality code and is used in a lot of industries. You don't have to worry about knowing how this works, but if you're curious, engage with a volunteer to find out more! :) + +1. Complete the challenges in each file and save it once you're happy with your changes +2. Run the script to check the results against the tests - all tests should read PASSED if you completed the challenges correctly. If a test reads FAILED, find the associated test to identify which function failed and fix it. +3. Raise a PR once you're happy with the quality of your code diff --git a/package.json b/package.json index 2bef6f48..7377b3f8 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,21 @@ -{ - "name": "javascript-core-2-coursework-week1-london8", - "version": "1.0.0", - "description": "Exercises for JS2 Week 1", - "license": "CC-BY-SA-4.0", - "scripts": { - "test": "jest --testRegex='mandatory[/\\\\].*\\.js$' --testPathIgnorePatterns='1-recipes.js'", - "extra-tests": "jest --testRegex='extra[/\\\\].*\\.js$'" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/CodeYourFuture/JavaScript-Core-2-Coursework-Week1-London8.git" - }, - "bugs": { - "url": "https://github.com/CodeYourFuture/JavaScript-Core-2-Coursework-Week1-London8/issues" - }, - "homepage": "https://github.com/CodeYourFuture/JavaScript-Core-2-Coursework-Week1-London8#readme", - "devDependencies": { - "jest": "^26.6.3" - } -} +{ + "name": "javascript-core-2-coursework-week1-london8", + "version": "1.0.0", + "description": "Exercises for JS2 Week 1", + "license": "CC-BY-SA-4.0", + "scripts": { + "test": "jest --testRegex='mandatory[/\\\\].*\\.js$' --testPathIgnorePatterns='1-recipes.js'", + "extra-tests": "jest --testRegex='extra[/\\\\].*\\.js$'" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/CodeYourFuture/JavaScript-Core-2-Coursework-Week1-London8.git" + }, + "bugs": { + "url": "https://github.com/CodeYourFuture/JavaScript-Core-2-Coursework-Week1-London8/issues" + }, + "homepage": "https://github.com/CodeYourFuture/JavaScript-Core-2-Coursework-Week1-London8#readme", + "devDependencies": { + "jest": "^26.6.3" + } +}