From d713916377203bed0f735af110565366ff61b9f9 Mon Sep 17 00:00:00 2001 From: edksam Date: Sun, 6 Sep 2020 22:42:59 +0100 Subject: [PATCH 1/9] Initial Commit --- .../mandatory/0-thinking-like-a-programmer/task.md | 9 +++++++++ .../mandatory/1-debugging-practice/script.js | 12 ++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) 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..18c05e6 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 @@ -28,10 +28,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..68b1f0d 100644 --- a/week-1/Homework/mandatory/1-debugging-practice/script.js +++ b/week-1/Homework/mandatory/1-debugging-practice/script.js @@ -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 @@ -90,11 +90,11 @@ function 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("clicks", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From 1930b0340743c1aef382ea055e1f5ec361980d01 Mon Sep 17 00:00:00 2001 From: edksam Date: Mon, 7 Sep 2020 00:33:45 +0100 Subject: [PATCH 2/9] Changes made - debugged --- week-1/Homework/mandatory/1-debugging-practice/script.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/week-1/Homework/mandatory/1-debugging-practice/script.js b/week-1/Homework/mandatory/1-debugging-practice/script.js index 68b1f0d..4c4bb36 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.check); + myLibrary.push(book); render(); } } @@ -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"; @@ -94,7 +94,7 @@ function render() { cell5.appendChild(delButton); delButton.className = "btn btn-warning"; delButton.innerHTML = "Delete"; - delButton.addEventListener("clicks", function () { + delButton.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From d0e65049f27dd9da5cabcb3f691368d43ca15f7e Mon Sep 17 00:00:00 2001 From: edksam Date: Mon, 7 Sep 2020 00:54:30 +0100 Subject: [PATCH 3/9] Changes made - debugged --- week-1/Homework/mandatory/1-debugging-practice/script.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week-1/Homework/mandatory/1-debugging-practice/script.js b/week-1/Homework/mandatory/1-debugging-practice/script.js index 4c4bb36..9a299ff 100644 --- a/week-1/Homework/mandatory/1-debugging-practice/script.js +++ b/week-1/Homework/mandatory/1-debugging-practice/script.js @@ -37,7 +37,7 @@ function submit() { alert("Please fill all fields!"); return false; } else { - let book = new Book(title.value, author.value, pages.value, check.check); + let book = new Book(title.value, author.value, pages.value, check.checked); myLibrary.push(book); render(); } @@ -76,7 +76,7 @@ function render() { changeBut.className = "btn btn-success"; cell4.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == true) { + if (myLibrary[i].check === true) { readStatus = "Yes"; } else { readStatus = "No"; @@ -84,7 +84,7 @@ function render() { changeBut.innerHTML = readStatus; changeBut.addEventListener("click", function () { - myLibrary[i].check = !myLibrary[i].check; + myLibrary[i].check ===!myLibrary[i].check; render(); }); From 8b2ec3c0f5443f9c89da23cd63f40c2bf7cb6f3d Mon Sep 17 00:00:00 2001 From: edksam Date: Tue, 27 Oct 2020 22:12:18 +0000 Subject: [PATCH 4/9] Git syncing corrections --- week-3/Homework/mandatory/2-exercises/1-shopping-cart.js | 1 + 1 file changed, 1 insertion(+) diff --git a/week-3/Homework/mandatory/2-exercises/1-shopping-cart.js b/week-3/Homework/mandatory/2-exercises/1-shopping-cart.js index d58a051..d978f1b 100644 --- a/week-3/Homework/mandatory/2-exercises/1-shopping-cart.js +++ b/week-3/Homework/mandatory/2-exercises/1-shopping-cart.js @@ -13,6 +13,7 @@ class ShoppingCart { // Add your code here cartContains() { + console.log() // Use console.log() to output everything contained in your cart } } From 8a35713c365b176761cf91f1dc14f79c4b99f662 Mon Sep 17 00:00:00 2001 From: edksam Date: Sun, 6 Sep 2020 22:42:59 +0100 Subject: [PATCH 5/9] Initial Commit --- .../mandatory/0-thinking-like-a-programmer/task.md | 9 +++++++++ .../mandatory/1-debugging-practice/script.js | 12 ++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) 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..68b1f0d 100644 --- a/week-1/Homework/mandatory/1-debugging-practice/script.js +++ b/week-1/Homework/mandatory/1-debugging-practice/script.js @@ -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 @@ -90,11 +90,11 @@ function 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("clicks", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From 015d611df7b55d2be8ee1db374a476c2465ca94b Mon Sep 17 00:00:00 2001 From: edksam Date: Mon, 7 Sep 2020 00:33:45 +0100 Subject: [PATCH 6/9] Changes made - debugged --- week-1/Homework/mandatory/1-debugging-practice/script.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/week-1/Homework/mandatory/1-debugging-practice/script.js b/week-1/Homework/mandatory/1-debugging-practice/script.js index 68b1f0d..4c4bb36 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.check); + myLibrary.push(book); render(); } } @@ -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"; @@ -94,7 +94,7 @@ function render() { cell5.appendChild(delButton); delButton.className = "btn btn-warning"; delButton.innerHTML = "Delete"; - delButton.addEventListener("clicks", function () { + delButton.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From 078c822c83960a48c13a9aa9a2210ed32b0eba43 Mon Sep 17 00:00:00 2001 From: edksam Date: Mon, 7 Sep 2020 00:54:30 +0100 Subject: [PATCH 7/9] Changes made - debugged --- week-1/Homework/mandatory/1-debugging-practice/script.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week-1/Homework/mandatory/1-debugging-practice/script.js b/week-1/Homework/mandatory/1-debugging-practice/script.js index 4c4bb36..9a299ff 100644 --- a/week-1/Homework/mandatory/1-debugging-practice/script.js +++ b/week-1/Homework/mandatory/1-debugging-practice/script.js @@ -37,7 +37,7 @@ function submit() { alert("Please fill all fields!"); return false; } else { - let book = new Book(title.value, author.value, pages.value, check.check); + let book = new Book(title.value, author.value, pages.value, check.checked); myLibrary.push(book); render(); } @@ -76,7 +76,7 @@ function render() { changeBut.className = "btn btn-success"; cell4.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == true) { + if (myLibrary[i].check === true) { readStatus = "Yes"; } else { readStatus = "No"; @@ -84,7 +84,7 @@ function render() { changeBut.innerHTML = readStatus; changeBut.addEventListener("click", function () { - myLibrary[i].check = !myLibrary[i].check; + myLibrary[i].check ===!myLibrary[i].check; render(); }); From 9147306f852bfa13923bd30116c917f86b1847fc Mon Sep 17 00:00:00 2001 From: edksam Date: Tue, 27 Oct 2020 22:12:18 +0000 Subject: [PATCH 8/9] Git syncing corrections --- .../mandatory/2-exercises/1-shopping-cart.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 week-3/Homework/mandatory/2-exercises/1-shopping-cart.js 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(); From 758eafacb3ab427e3c343d13ef58dd1d911b4b03 Mon Sep 17 00:00:00 2001 From: edksam Date: Wed, 28 Oct 2020 00:05:30 +0000 Subject: [PATCH 9/9] Changes from remote exercises --- .../2-exercises/exercise-1/exercise-1.js | 16 ++-- .../2-exercises/exercise-2/exercise-2.js | 96 +++++++++++++++++-- .../2-exercises/exercise-3/exercise-3.js | 34 +++++-- 3 files changed, 121 insertions(+), 25 deletions(-) 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);