From 801d4b246a7637ced870a530ea4d1366a0665e34 Mon Sep 17 00:00:00 2001
From: MartinBoylan <63868146+MartinBoylan@users.noreply.github.com>
Date: Thu, 24 Sep 2020 12:35:40 +0100
Subject: [PATCH 1/2] JScore3week3 homework
---
week-3/.vscode/settings.json | 15 +++++++
.../mandatory/1-practice/2-code-reading.md | 6 +++
week-3/Homework/mandatory/1-practice/app.js | 24 +++++++++++
.../Homework/mandatory/1-practice/index.html | 23 ++++++++++
.../Homework/mandatory/1-practice/style.css | 42 +++++++++++++++++++
.../2-exercises/exercise-1/exercise-1.js | 18 ++++----
.../2-exercises/exercise-2/exercise-2.js | 18 ++++++++
.../2-exercises/exercise-2/exercise-2.md | 29 +++++++++----
.../2-exercises/exercise-3/exercise-3.js | 35 ++++++++++++----
9 files changed, 185 insertions(+), 25 deletions(-)
create mode 100644 week-3/.vscode/settings.json
create mode 100644 week-3/Homework/mandatory/1-practice/app.js
create mode 100644 week-3/Homework/mandatory/1-practice/index.html
create mode 100644 week-3/Homework/mandatory/1-practice/style.css
diff --git a/week-3/.vscode/settings.json b/week-3/.vscode/settings.json
new file mode 100644
index 0000000..27447b3
--- /dev/null
+++ b/week-3/.vscode/settings.json
@@ -0,0 +1,15 @@
+{
+ "cSpell.words": [
+ "Albus",
+ "Diggory",
+ "Flitwick",
+ "Gonagall",
+ "Gryffindor",
+ "Hermione",
+ "Hufflepuff",
+ "Malfoy",
+ "Ravenclaw",
+ "Slytherin",
+ "Snape"
+ ]
+}
\ No newline at end of file
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..8191e9b 100644
--- a/week-3/Homework/mandatory/1-practice/2-code-reading.md
+++ b/week-3/Homework/mandatory/1-practice/2-code-reading.md
@@ -14,6 +14,7 @@ Take a look at the following code:
```
Explain why line 4 and line 6 output different numbers.
+They have different scope. line 4 is within the curly braces and gets defined using let so x is only 2 within those curly braces.
## Question 2
@@ -33,6 +34,8 @@ console.log(y)
```
What will be the output of this code. Explain your answer in 50 words or less.
+10, undefined
+x gets assigned 10 and is then consoled from within the function which is called on line 32. y is defined as y inside the function so the y which is console logged is not defined within the global scope so is undefined.
## Question 3
@@ -61,3 +64,6 @@ console.log(y);
```
What will be the output of this code. Explain your answer in 50 words or less.
+9
+{x:9}
+the f1 function is called with 9 as the argument. Although this function returns 10 that is not consoled. the x defined on line 44 is consoled.Its the same for the object passed into the function f2. What is consoled is the const assigned the object on line 54.
diff --git a/week-3/Homework/mandatory/1-practice/app.js b/week-3/Homework/mandatory/1-practice/app.js
new file mode 100644
index 0000000..ade8d11
--- /dev/null
+++ b/week-3/Homework/mandatory/1-practice/app.js
@@ -0,0 +1,24 @@
+/* got an error 429 - too many requests. Tried using this https://openweathermap.org/api. but could not get it to work with the proxy */
+
+window.addEventListener("load", () => {
+ let long;
+ let lat;
+ if (navigator.geolocation) {
+ navigator.geolocation.getCurrentPosition((position) => {
+ long = position.coords.longitude;
+ lat = position.coords.latitude;
+
+ /* const key = `1487bcd90d23b6e404ba291d04177780`; */
+ const proxy = "https://cors-anywhere.herokuapp.com/";
+ //Got an error 429.
+ const api = `${proxy}https://api.darksky.net/forecast/fd9d9c6418c23d94745b836767721ad1/${lat},${long}`;
+ fetch(api)
+ .then((response) => {
+ return response.json();
+ })
+ .then((data) => {
+ console.log(data);
+ });
+ });
+ }
+});
diff --git a/week-3/Homework/mandatory/1-practice/index.html b/week-3/Homework/mandatory/1-practice/index.html
new file mode 100644
index 0000000..b3d3219
--- /dev/null
+++ b/week-3/Homework/mandatory/1-practice/index.html
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+ Weather
+
+
+
+
Timezone
+
Icon
+
+
+
+
+
34
+ F
+
Its cold
+
+
+
+
\ No newline at end of file
diff --git a/week-3/Homework/mandatory/1-practice/style.css b/week-3/Homework/mandatory/1-practice/style.css
new file mode 100644
index 0000000..806defd
--- /dev/null
+++ b/week-3/Homework/mandatory/1-practice/style.css
@@ -0,0 +1,42 @@
+* {
+ margin: 0;
+ padding: 0;
+ box-sizing: border-box;
+}
+
+body {
+ height: 100vh;
+ display: flex;
+ justify-content: center;
+ flex-direction: column;
+ align-items: center;
+ background: linear-gradient(rgb(47, 150, 163), rgb(48,62,143));
+ font-family: sans-serif;
+ color: white;
+}
+.location,
+.temperature {
+ height: 30vh;
+ width: 50%;
+ display: flex;
+ justify-content: space-around;
+ align-items: center;
+
+}
+.temperature {
+ flex-direction: column;
+}
+.degree-section {
+ display: flex;
+ align-items: center;
+ cursor: pointer;
+}
+.degree-section span {
+ margin: 10px;
+ font-size: 30px;
+
+}
+.degree-section h2 {
+ font-size: 40px;
+}
+
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..381d6b6 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',
+let personOne = {
+ name: "Popeye",
age: 34,
- favouriteFood: 'Spinach'
-}
+ favoriteFood: "Spinach",
+};
+
+let { name, age, favoriteFood } = personOne;
-function introduceYourself(___________________________) {
- console.log (`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`);
+function introduceYourself(name, age, favoriteFood) {
+ console.log(
+ `Hello, my name is ${name}. I am ${age} years old and my favorite food is ${favoriteFood}.`
+ );
}
-introduceYourself(personOne);
\ No newline at end of file
+introduceYourself(name, age, favoriteFood);
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..2733fed 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,21 @@ let hogwarts = [
{ firstName: "Minerva", lastName: "McGonagall", house: "Gryffindor", pet: null, occupation: "Teacher" },
{ firstName: "Albus", lastName: "Dumbledore", house: "Gryffindor", pet: "Phoenix", occupation: "Teacher" }
]
+
+
+let [firstName, lastName, house, pet, occupation] = hogwarts;
+
+hogwarts.forEach(function (wizard) {
+ if (wizard.house === "Slytherin") {
+ console.log(`${wizard.firstName} ${wizard.lastName}`);
+ }
+});
+
+function displayTeachersWithPets(hogwarts) {
+ hogwarts.forEach(function (wizard) {
+ if (wizard.pet !== null && wizard.occupation === "Teacher") {
+ console.log(`${wizard.firstName} ${wizard.lastName}`);
+ }
+ });
+}
+displayTeachersWithPets(hogwarts);
\ No newline at end of file
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
index 12b8948..f53c62a 100644
--- a/week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.md
+++ b/week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.md
@@ -5,17 +5,26 @@ _Need some help? Refresh your memory with [this article](https://www.freecodecam
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
+- 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.
+- 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.
+let [firstName, lastName, house, pet, occupation] = hogwarts;
+
+hogwarts.forEach(function (wizard) {
+ if (wizard.house === "Gryffindor") {
+console.log(`${wizard.firstName} ${wizard.lastName}`)
+
+ }
+}
+)
### Expected result
```
@@ -28,11 +37,13 @@ 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.
+- 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
index b60d527..5858286 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,26 @@
- 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 },
+];
+let total = 0;
+function printReceipt(item) {
+ console.log(`QTY ITEM TOTAL `);
+
+ order.forEach(function (item) {
+ let { itemName, quantity, unitPrice } = item;
+ total = total + unitPrice * quantity;
+ console.log(
+ `${item.quantity} ${item.itemName} ${(
+ item.unitPrice * item.quantity
+ ).toFixed(2)}`
+ );
+ });
+
+ console.log(`TOTAL: ${total}`);
+}
+
+printReceipt(order);
From 0cc4c7fdc6ed1189d4c5142108eda343689fb364 Mon Sep 17 00:00:00 2001
From: MartinBoylan <63868146+MartinBoylan@users.noreply.github.com>
Date: Fri, 25 Sep 2020 13:53:29 +0100
Subject: [PATCH 2/2] JS 3 week 3homework
---
.DS_Store | Bin 0 -> 6148 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 .DS_Store
diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..e16e2fb771a29def850a0b99b51f557fbb871269
GIT binary patch
literal 6148
zcmeHKJB|V|47C9vB$_F=%mpY`Tp&Vl0xp1dfrgbR5Tc!mb8$4DKLw-N?brhJJaS&*
z_+>P&h{qzLi}UtVq!Ez`+)%DI^v(9odp5|30^vAgCiDIF^!;@_{`9hc4;XhW7un%C
zJo0UWMg^z<6`%rCfC@Zafh@6;>C;c6`G>cHSF0C0q`8|L0i
z0E-2HHL(pu1g1d+2351g(4Zq;GOs4Kfk79|=0o$%njMPz+i`yJbkQ2fkqS_Ot^&hY
zHdg;v@IU(hE{Q8DKn31P0Ua&Z%LP6uYisZ0tkxFz25vbwxEbb7!QkZ>=;as-E5{$6
b6nVww*sqCgpwkg|I*>mDrVEV<{I>#kh2s>N
literal 0
HcmV?d00001