From dbd8b247f4d94b8e0dfdfc8a5ef9e47446ec5849 Mon Sep 17 00:00:00 2001 From: Denis-Andrei Date: Mon, 7 Sep 2020 12:09:37 +0100 Subject: [PATCH 1/7] Mandatory Homework done --- .../0-thinking-like-a-programmer/task.md | 4 ++++ .../mandatory/1-debugging-practice/script.js | 20 +++++++++---------- 2 files changed, 14 insertions(+), 10 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..8e8e034 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 @@ -27,11 +27,15 @@ After you've watched these videos I'd like you to answer these questions ## 1. What do you think the most important quality for a programmer is? +The most important quality of a programmer is problem solving skill. Learning and knowing the syntax of a programming language will not be very useful if you don't train your mind to solve problems. ## 2. When trying to solve a challenge, what should you do first? +I think the first step when you try to solve a challenge is to understand the requirements. Understanding the requirements will prevent you from wasting time trying solutions. ## 3. What should you do if you get stuck? + +If you get stuck you should start debugging the code. If debugging doesn't solve the problem try to take a step back and try to look at the problem form a different perspective. diff --git a/week-1/Homework/mandatory/1-debugging-practice/script.js b/week-1/Homework/mandatory/1-debugging-practice/script.js index dc14a77..b840749 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 @@ -77,9 +77,9 @@ function render() { cell4.appendChild(changeBut); let readStatus = ""; if (myLibrary[i].check == false) { - readStatus = "Yes"; - } else { readStatus = "No"; + } else { + readStatus = "Yes"; } changeBut.innerHTML = readStatus; @@ -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("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From 12627dc5f34d8bbb390b4ff2eb789760c681d186 Mon Sep 17 00:00:00 2001 From: Denis-Andrei Date: Mon, 7 Sep 2020 12:14:08 +0100 Subject: [PATCH 2/7] Revert "Mandatory Homework done" This reverts commit dbd8b247f4d94b8e0dfdfc8a5ef9e47446ec5849. --- .../0-thinking-like-a-programmer/task.md | 4 ---- .../mandatory/1-debugging-practice/script.js | 20 +++++++++---------- 2 files changed, 10 insertions(+), 14 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 8e8e034..1c841f8 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 @@ -27,15 +27,11 @@ After you've watched these videos I'd like you to answer these questions ## 1. What do you think the most important quality for a programmer is? -The most important quality of a programmer is problem solving skill. Learning and knowing the syntax of a programming language will not be very useful if you don't train your mind to solve problems. ## 2. When trying to solve a challenge, what should you do first? -I think the first step when you try to solve a challenge is to understand the requirements. Understanding the requirements will prevent you from wasting time trying solutions. ## 3. What should you do if you get stuck? - -If you get stuck you should start debugging the code. If debugging doesn't solve the problem try to take a step back and try to look at the problem form a different perspective. diff --git a/week-1/Homework/mandatory/1-debugging-practice/script.js b/week-1/Homework/mandatory/1-debugging-practice/script.js index b840749..dc14a77 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, author.value, pages.value, check.checked); - myLibrary.push(book); + let book = new Book(title.value, title.value, pages.value, check.checked); + library.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 @@ -77,9 +77,9 @@ function render() { cell4.appendChild(changeBut); let readStatus = ""; if (myLibrary[i].check == false) { - readStatus = "No"; - } else { readStatus = "Yes"; + } else { + readStatus = "No"; } changeBut.innerHTML = readStatus; @@ -90,11 +90,11 @@ function render() { //add delete button to every row and render again let delButton = document.createElement("button"); - delButton.id = i + 5; - cell5.appendChild(delButton); - delButton.className = "btn btn-warning"; - delButton.innerHTML = "Delete"; - delButton.addEventListener("click", function () { + delBut.id = i + 5; + cell5.appendChild(delBut); + delBut.className = "btn btn-warning"; + delBut.innerHTML = "Delete"; + delBut.addEventListener("clicks", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From d6ce0539b0287956ebb37c1c926abfbf36d20606 Mon Sep 17 00:00:00 2001 From: Denis-Andrei Date: Fri, 18 Sep 2020 21:58:35 +0100 Subject: [PATCH 3/7] 1-practice DONE --- .../Homework/mandatory/1-practice/2-code-reading.md | 11 ++++++++++- .../mandatory/2-exercises/exercise-1/exercise-1.js | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) 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..45de7f3 100644 --- a/week-3/Homework/mandatory/1-practice/2-code-reading.md +++ b/week-3/Homework/mandatory/1-practice/2-code-reading.md @@ -15,6 +15,9 @@ Take a look at the following code: Explain why line 4 and line 6 output different numbers. +They output different numbers because the scopes of the x variable are different. + + ## Question 2 Take a look at the following code: @@ -34,7 +37,9 @@ console.log(y) What will be the output of this code. Explain your answer in 50 words or less. -## Question 3 +The output of this code will be 10 and undefined. The x variable have a global scope which means can be accessed inside other scopes. The y variable it's defined inside a functions scope and we are trying to display it outside of the function( where it's scope is not recognised). + +## Question 3 Take a look at the following code: @@ -61,3 +66,7 @@ console.log(y); ``` What will be the output of this code. Explain your answer in 50 words or less. + +The output of the code will be x = 9 and y = 10. +X is a integer const and cannot be changed. +Y is a const object but we can change the value of the x inside. If we try to reasign the y object then this will throw an error. 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..dbce828 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 @@ -8,4 +8,4 @@ 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 +introduceYourself(personOne); \ No newline at end of file From 5461f6668aedee4ec3d8960990fb10a0856f382c Mon Sep 17 00:00:00 2001 From: Denis-Andrei Date: Fri, 18 Sep 2020 22:02:56 +0100 Subject: [PATCH 4/7] 1st exercise DONE --- .../Homework/mandatory/2-exercises/exercise-1/exercise-1.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 dbce828..82d6bad 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 @@ -4,7 +4,9 @@ const personOne = { favouriteFood: 'Spinach' } -function introduceYourself(___________________________) { +const {name, age, favouriteFood} = personOne; //answer to question 1 + +function introduceYourself({name, age, favouriteFood}) { console.log (`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`); } From 3e12e08fcf915f2cf4c3df7459797c6ce1dfff4b Mon Sep 17 00:00:00 2001 From: Denis-Andrei Date: Fri, 18 Sep 2020 22:12:59 +0100 Subject: [PATCH 5/7] 2nd exercise DONE --- .../mandatory/2-exercises/exercise-2/exercise-2.js | 11 +++++++++++ 1 file changed, 11 insertions(+) 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..0da3068 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 @@ -9,3 +9,14 @@ let hogwarts = [ { firstName: "Minerva", lastName: "McGonagall", house: "Gryffindor", pet: null, occupation: "Teacher" }, { firstName: "Albus", lastName: "Dumbledore", house: "Gryffindor", pet: "Phoenix", occupation: "Teacher" } ] + + + + +hogwarts.forEach(({firstName, lastName, house}) => { + house === 'Gryffindor' ? console.log(`${firstName} ${lastName}`) : ''; +}) + +hogwarts.forEach(({firstName, lastName, pet, occupation}) => { + pet && occupation === 'Teacher' ? console.log(`${firstName} ${lastName}`) : ''; +}) \ No newline at end of file From 62c84f1448716bce05228e31638d99595b3bc561 Mon Sep 17 00:00:00 2001 From: Denis-Andrei Date: Fri, 18 Sep 2020 22:23:20 +0100 Subject: [PATCH 6/7] 3rd exercise DONE --- .../mandatory/2-exercises/exercise-3/exercise-3.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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..4f7ffc7 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 @@ -6,4 +6,13 @@ { itemName: "Hot Coffee", quantity: 2, unitPrice: 1.00}, { itemName: "Hash Brown", quantity: 4, unitPrice: 0.40} ] - \ No newline at end of file + + let totalPrice = 0; + + console.log(`QTY ITEM TOTAL`); + order.forEach(({itemName, quantity, unitPrice}) => { + console.log(`${quantity} ${itemName} ${unitPrice}`); + totalPrice += unitPrice; + }) + + console.log(totalPrice); \ No newline at end of file From 98dd9a3fa49c36a59030f6b102a74902616ee333 Mon Sep 17 00:00:00 2001 From: Denis-Andrei Date: Fri, 18 Sep 2020 22:24:36 +0100 Subject: [PATCH 7/7] 3rd exercise updated --- week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4f7ffc7..b9c23b8 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 @@ -15,4 +15,4 @@ totalPrice += unitPrice; }) - console.log(totalPrice); \ No newline at end of file + console.log(`Total: ${totalPrice}`); \ No newline at end of file