diff --git a/week-1/Homework/mandatory/0-thinking-like-a-programmer/task.md b/week-1/Homework/mandatory/0-thinking-like-a-programmer/task.md index 1c841f8..d2b9f40 100644 --- a/week-1/Homework/mandatory/0-thinking-like-a-programmer/task.md +++ b/week-1/Homework/mandatory/0-thinking-like-a-programmer/task.md @@ -2,7 +2,9 @@ ## 1. Install ESLint -Using ESLint can make debugging a lot easier. If you haven't already you should install it now. +ESLint is what is called an static analysis tool. It checks your code for common mistakes that can impact code quality and styling. + +If you haven't already you should install it now. https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint @@ -12,8 +14,9 @@ During these past weeks you have gotten a taste of what programming is: the vari Thinking like a programmer is very similar to thinking like a construction worker: -You have to build something and it's up to you to know all the necessary tools and techniques to make that happen, and -You have to solve every problem that comes up along the way (such as things that go wrong, knowing how to choose the right tools for the job and striving to achieve the right goal) +* You have to build something and it's up to you to know all the necessary tools and techniques to make that happen, and +* You have to solve every problem that comes up along the way (such as things that go wrong, knowing how to choose the right tools for the job and striving to achieve the right goal) + The second skill, problem solving, is the most important one. If you get good at that, you'll automatically get good at the first. Take a look at the following resources to learn more about problem solving as applied to programming: diff --git a/week-1/Homework/mandatory/1-debugging-practice/task.md b/week-1/Homework/mandatory/1-debugging-practice/task.md index ccb7c99..d73db65 100644 --- a/week-1/Homework/mandatory/1-debugging-practice/task.md +++ b/week-1/Homework/mandatory/1-debugging-practice/task.md @@ -13,7 +13,7 @@ My website should be able to: 1. Website loads but nothing works in my javascript 2. Website loads but nothing happens 3. Error in console when you try to add a book -4. It uses the title name as the author name. +4. It uses the title name as the author name 5. Delete button is broken 6. When I add a book that I say I've read - it saves the wrong answer diff --git a/week-3/Homework/mandatory/1-practice/2-code-reading.md b/week-3/Homework/mandatory/1-practice/2-code-reading.md index 295964e..72651a2 100644 --- a/week-3/Homework/mandatory/1-practice/2-code-reading.md +++ b/week-3/Homework/mandatory/1-practice/2-code-reading.md @@ -6,11 +6,12 @@ Take a look at the following code: ``` 1 let x = 1; -2 { -3 let x = 2; -4 console.log(x); -5 } -6 console.log(x); +2 function f1() +3 { +4 let x = 2; +5 console.log(x); +6 } +7 console.log(x); ``` Explain why line 4 and line 6 output different numbers. diff --git a/week-3/Homework/mandatory/2-exercises/1-shopping-cart.js b/week-3/Homework/mandatory/2-exercises/1-shopping-cart.js deleted file mode 100644 index d58a051..0000000 --- a/week-3/Homework/mandatory/2-exercises/1-shopping-cart.js +++ /dev/null @@ -1,26 +0,0 @@ -/* - -Complete the rest of this code to create an online shopping cart. - -The output of running your code should be: - - Your shopping cart has 3 items: Toilet Roll, Pasta, Eggs - - -*/ - -class ShoppingCart { - // Add your code here - - cartContains() { - // Use console.log() to output everything contained in your cart - } -} - -let myCart = new ShoppingCart(); // Creates an empty shopping cart - -myCart.addItem("Toilet Roll"); -myCart.addItem("Pasta"); -myCart.addItem("Eggs"); - -myCart.cartContains(); diff --git a/week-3/Homework/mandatory/2-exercises/2-convertion.js b/week-3/Homework/mandatory/2-exercises/2-convertion.js deleted file mode 100644 index 4c338c9..0000000 --- a/week-3/Homework/mandatory/2-exercises/2-convertion.js +++ /dev/null @@ -1,30 +0,0 @@ -/* - Convert the Function here into a JavaScript Class called 'Person' - - ``` - function createNewPerson(name) { - const obj = {}; - obj.name = name; - obj.greeting = function() { - alert('Hi! I\'m ' + obj.name + '.'); - }; - return obj; - } - - const simon = createNewPerson('simon'); - simon.name; - simon.greeting() - ``` - - When you run this code using `node 2-convertion.js` you should be able to - - -*/ - -// Write your code here - -// Do not edit this section -const simon = new Person("simon"); -console.log(simon.name); -simon.greeting(); -// Do not edit this section diff --git a/week-3/Homework/mandatory/2-exercises/3-atm.js b/week-3/Homework/mandatory/2-exercises/3-atm.js deleted file mode 100644 index 768bce4..0000000 --- a/week-3/Homework/mandatory/2-exercises/3-atm.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - - Create a simple ATM machine. - - Your ATM should allow you to: - - Deposit money - - Withdraw money - - Check your balance. - - You should start with a balance of 100.0 pounds in your account. - - */ - -class ATM { - // Add your code here - -} - -let atm = new ATM(); // Create the ATM - -atm.make_deposit(200); -atm.check_balance(); -atm.make_withdrawl(100); - -atm.make_withdrawl(500); // Your ATM should be able to handle this scenario \ No newline at end of file diff --git a/week-3/Homework/mandatory/2-exercises/4-music-player.js b/week-3/Homework/mandatory/2-exercises/4-music-player.js deleted file mode 100644 index 17f4a2d..0000000 --- a/week-3/Homework/mandatory/2-exercises/4-music-player.js +++ /dev/null @@ -1,50 +0,0 @@ -class MusicPlayer { - // Add your code here - -} - -let myMusicPlayer = new MusicPlayer(); // Create an empty playlist - -// Add some songs to your playlist -myMusicPlayer.add("Bohemian Rhapsody","Queen"); -myMusicPlayer.add("Yesterday","The Beatles"); -myMusicPlayer.add("Vogue","Madonna"); - -myMusicPlayer.play(); // Output: "Currently playing: Bohemian Rhapsody by Queen" - -myMusicPlayer.skip(); // Output: "Currently playing: Yesterday by The Beatles" - -myMusicPlayer.previous(); // Output: "Currently playing: Bohemian Rhapsody by Queen" - -myMusicPlayer.skip(); // Output: "Currently playing: Yesterday by The Beatles" - -myMusicPlayer.skip(); // Output: "Currently playing: Vogue by Madonna" - - -/* - - -Task 1: Complete the above code to create a music player that will run through a playlist of songs and output to the console as described in the comments. - -Task 2: Add some extra logic to handle these 2 scenarios: -- Trying to call myMusicPlayer.play() if there are no songs in the playlist -- Trying to call myMusicPlayer.skip() when there are no songs left to play - - - -Optional 1: Your music player stops once you have reached the end of the playlist. -Can you implement the 'repeat' functionality so that it starts again from the beginning instead of stopping? - - -Optional 2: Can you implement the shuffle functionality for your music player? -This means the order the songs are played in will be random, but each song will only play once. - - */ - - - - - - - - diff --git a/week-3/Homework/mandatory/2-exercises/exercise-1/exercise-1.js b/week-3/Homework/mandatory/2-exercises/exercise-1/exercise-1.js new file mode 100644 index 0000000..10b93ba --- /dev/null +++ b/week-3/Homework/mandatory/2-exercises/exercise-1/exercise-1.js @@ -0,0 +1,11 @@ +const personOne = { + name: 'Popeye', + age: 34, + favouriteFood: 'Spinach' +} + +function introduceYourself(___________________________) { + console.log (`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`); +} + +introduceYourself(personOne); \ No newline at end of file diff --git a/week-3/Homework/mandatory/2-exercises/exercise-1/exercise-1.md b/week-3/Homework/mandatory/2-exercises/exercise-1/exercise-1.md new file mode 100644 index 0000000..9c3ac97 --- /dev/null +++ b/week-3/Homework/mandatory/2-exercises/exercise-1/exercise-1.md @@ -0,0 +1,21 @@ +Did you know that destructuring can also be used on objects as well. + +We can use destructuring to extract values from an object and assign them to variables in one line. + +``` +let person = { + firstName: "Bruce", + lastName: "Wayne" +} + +let { firstName, lastName } = person; + +console.log(`Batman is ${firstName}, ${lastName}`); +``` + +The program above will print `Batman is Bruce Wayne`. Notice how we use the `{}` characters since it is an object rather than `[]` which is used when it is an array. + +# Exercise + +- What is the syntax to destructure the object `personOne` in exercise-1.js? +- Update the argument of the function `introduceYourself` to use destructuring on the object that gets passed in. diff --git a/week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.js b/week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.js new file mode 100644 index 0000000..0d3ade0 --- /dev/null +++ b/week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.js @@ -0,0 +1,11 @@ +let hogwarts = [ + { firstName: "Harry", lastName: "Potter", house: "Gryffindor", pet: "Owl", occupation: "Student" }, + { firstName: "Hermione", lastName: "Granger", house: "Gryffindor", pet: "Cat", occupation: "Student" }, + { firstName: "Draco", lastName: "Malfoy", house: "Slytherin", pet: null, occupation: "Student" }, + { firstName: "Cedric", lastName: "Diggory", house: "HufflePuff", pet: null, occupation: "Student" }, + { firstName: "Severus", lastName: "Snape", house: "Slytherin", pet: null, occupation: "Teacher" }, + { firstName: "Filius", lastName: "Flitwick", house: "Ravenclaw", pet: null, occupation: "Teacher" }, + { firstName: "Pomona", lastName: "Sprout", house: "Hufflepuff", pet: null, occupation: "Teacher" }, + { firstName: "Minerva", lastName: "McGonagall", house: "Gryffindor", pet: null, occupation: "Teacher" }, + { firstName: "Albus", lastName: "Dumbledore", house: "Gryffindor", pet: "Phoenix", occupation: "Teacher" } +] diff --git a/week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.md b/week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.md new file mode 100644 index 0000000..12b8948 --- /dev/null +++ b/week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.md @@ -0,0 +1,38 @@ +# Exercise 2 + +_Need some help? Refresh your memory with [this article](https://www.freecodecamp.org/news/array-destructuring-in-es6-30e398f21d10/)_ + +In `exercise-2.js`, you have an array that contains a list of people who are at Hogwarts School of Witchcraft and Wizardry. +For each character you have the following information: + +- First Name +- Last Name +- School House +- Pet +- Occupation + +## Task 1 + +- In `exercise-2.js` write a program that will take the `hogwarts` array as input and display the names of the people who belong to the Gryffindor house. +- Use array destructuring to extract the values you need out of the array. + +### Expected result + +``` +Harry Potter +Ron Weasley +Hermione Granger +Minerva McGonagall +Albus Dumbledore +``` + +## Task 2 + +- In `exercise-2.js` write a program that will take the `hogwarts` array as input and display the names of teachers who have pets. +- Use array destructuring to extract the values you need out of the array. + +### Expected result + +``` +Albus Dumbledore +``` diff --git a/week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.js b/week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.js new file mode 100644 index 0000000..b60d527 --- /dev/null +++ b/week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.js @@ -0,0 +1,9 @@ + let order = [ + { itemName: "Hot cakes", quantity: 1, unitPrice: 2.29}, + { itemName: "Apple Pie", quantity: 2, unitPrice: 1.39}, + { itemName: "Egg McMuffin", quantity: 1, unitPrice: 2.80}, + { itemName: "Sausage McMuffin", quantity: 1, unitPrice: 3.00}, + { itemName: "Hot Coffee", quantity: 2, unitPrice: 1.00}, + { itemName: "Hash Brown", quantity: 4, unitPrice: 0.40} + ] + \ No newline at end of file diff --git a/week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.md b/week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.md new file mode 100644 index 0000000..e729ef2 --- /dev/null +++ b/week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.md @@ -0,0 +1,21 @@ +# Exercise + +_Need some help? Refresh your memory with [this article](https://www.freecodecamp.org/news/array-destructuring-in-es6-30e398f21d10/)_ + +- In `exercise-3.js`, you have been provided with a takeout order. Write a program that will print out the receipt for this order. +- Log each individual item to the console. +- Log the total cost of the order to the console. + +## Expected result + +``` +QTY ITEM TOTAL +1 Hot Cakes 2.29 +2 Apple Pie 2.78 +1 Egg McMuffin 2.80 +1 Sausage McMuffin 3.00 +2 Hot Coffee 2.00 +4 Hash Brown 1.60 + +Total: 14.47 +``` diff --git a/week-3/Homework/mandatory/2-exercises/resources.md b/week-3/Homework/mandatory/2-exercises/resources.md new file mode 100644 index 0000000..169a6a4 --- /dev/null +++ b/week-3/Homework/mandatory/2-exercises/resources.md @@ -0,0 +1,7 @@ +# Resources + +Here are some useful resources to help you understand this homework + +- [FreeCodeCamp's Intro To Array Destructuring](https://www.freecodecamp.org/news/array-destructuring-in-es6-30e398f21d10/) +- [Why Is Array/Object Destructuring So Useful And How To Use It (Video)](https://www.youtube.com/watch?v=NIq3qLaHCIs) +- [The Most In-Depth Yet Understandable ES6 Destructuring Tutorial](https://untangled.io/in-depth-es6-destructuring-with-assembled-avengers)