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 d2b9f40..b72bc44 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 @@ -31,10 +31,19 @@ After you've watched these videos I'd like you to answer these questions +To be a problem solver. To be able to think about a problem and come up with a solution. + ## 2. When trying to solve a challenge, what should you do first? +1. Try and understand your problem. +2. Try and visualise it and maybe do the rubber duckie thing. + ## 3. What should you do if you get stuck? + +You stop and take a break and the regroup. +Talk to a rubber duckie +Research google diff --git a/week-1/Homework/mandatory/1-debugging-practice/script.js b/week-1/Homework/mandatory/1-debugging-practice/script.js index dc14a77..9a299ff 100644 --- a/week-1/Homework/mandatory/1-debugging-practice/script.js +++ b/week-1/Homework/mandatory/1-debugging-practice/script.js @@ -37,8 +37,8 @@ function submit() { alert("Please fill all fields!"); return false; } else { - let book = new Book(title.value, title.value, pages.value, check.checked); - library.push(book); + let book = new Book(title.value, author.value, pages.value, check.checked); + myLibrary.push(book); render(); } } @@ -54,7 +54,7 @@ function render() { let table = document.getElementById("display"); let rowsNumber = table.rows.length; //delete old table - for (let n = rowsNumber - 1; n > 0; n-- { + for (let n = rowsNumber - 1; n > 0; n--) { table.deleteRow(n); } //insert updated row and cells @@ -76,7 +76,7 @@ function render() { changeBut.className = "btn btn-success"; cell4.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == false) { + if (myLibrary[i].check === true) { readStatus = "Yes"; } else { readStatus = "No"; @@ -84,17 +84,17 @@ function render() { changeBut.innerHTML = readStatus; changeBut.addEventListener("click", function () { - myLibrary[i].check = !myLibrary[i].check; + myLibrary[i].check ===!myLibrary[i].check; render(); }); //add delete button to every row and render again let delButton = document.createElement("button"); - delBut.id = i + 5; - cell5.appendChild(delBut); - delBut.className = "btn btn-warning"; - delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { + delButton.id = i + 5; + cell5.appendChild(delButton); + delButton.className = "btn btn-warning"; + delButton.innerHTML = "Delete"; + delButton.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); diff --git a/week-3/Homework/mandatory/2-exercises/1-shopping-cart.js b/week-3/Homework/mandatory/2-exercises/1-shopping-cart.js new file mode 100644 index 0000000..d978f1b --- /dev/null +++ b/week-3/Homework/mandatory/2-exercises/1-shopping-cart.js @@ -0,0 +1,27 @@ +/* + +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() { + console.log() + // 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/exercise-1/exercise-1.js b/week-3/Homework/mandatory/2-exercises/exercise-1/exercise-1.js index 10b93ba..1e1dbbe 100644 --- a/week-3/Homework/mandatory/2-exercises/exercise-1/exercise-1.js +++ b/week-3/Homework/mandatory/2-exercises/exercise-1/exercise-1.js @@ -1,11 +1,15 @@ const personOne = { - name: 'Popeye', - age: 34, - favouriteFood: 'Spinach' -} + name: "Ebenezer", + age: 110, + favouriteFood: "Brocolli", +}; + +const { name, age, favouriteFood } = personOne; function introduceYourself(___________________________) { - console.log (`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`); + 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 +introduceYourself(personOne); 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 index 0d3ade0..5a84d3f 100644 --- a/week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.js +++ b/week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.js @@ -1,11 +1,87 @@ 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" } -] + { + 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", + }, +]; + +function peopleGryffindor(arr) { + for (var i = 0; i < arr.length; ++i) { + let { firstName, lastName, house } = arr[i]; + if (house === "Gryffindor") { + console.log(`${firstName} ${lastName}`); + } + } +} + +peopleGryffindor(hogwarts); + +function petOwners(arr) { + for (var i = 0; i < arr.length; ++i) { + let { firstName, lastName, pet, occupation } = arr[i]; + if (pet !== null && occupation === "Teacher") { + console.log(`${firstName} ${lastName}`); + } + } +} + +petOwners(hogwarts); 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 index b60d527..855126f 100644 --- a/week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.js +++ b/week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.js @@ -1,9 +1,25 @@ - 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 +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.8 }, + { itemName: "Sausage McMuffin", quantity: 1, unitPrice: 3.0 }, + { itemName: "Hot Coffee", quantity: 2, unitPrice: 1.0 }, + { itemName: "Hash Brown", quantity: 4, unitPrice: 0.4 }, +]; + +function printReceipt(order) { + let totalPx = 0; + console.log(`QTY ITEM TOTAL`); + for (let i = 0; i < order.length; ++i) { + const { itemName, quantity, unitPrice } = order[i]; + totalPx += unitPrice; + if (itemName.length > 12) { + console.log(`${quantity} ${itemName} ${unitPrice.toFixed(2)}`); + } else { + console.log(`${quantity} ${itemName} ${unitPrice.toFixed(2)}`); + } + } + console.log(`Total: ${totalPx.toFixed(2)}`); +} + +printReceipt(order);