Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Js core3 wk3 hw mb #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
15 changes: 15 additions & 0 deletions week-3/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"cSpell.words": [
"Albus",
"Diggory",
"Flitwick",
"Gonagall",
"Gryffindor",
"Hermione",
"Hufflepuff",
"Malfoy",
"Ravenclaw",
"Slytherin",
"Snape"
]
}
6 changes: 6 additions & 0 deletions week-3/Homework/mandatory/1-practice/2-code-reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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.
24 changes: 24 additions & 0 deletions week-3/Homework/mandatory/1-practice/app.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
}
});
23 changes: 23 additions & 0 deletions week-3/Homework/mandatory/1-practice/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./style.css"/>
<title>Weather</title>
</head>
<body>
<div class = "location">
<h1 class = "location-timezone">Timezone</h1>
<p>Icon</p>
</div>
<div class="temperature">
<div class="degree-section">
</div>
<h2 class="temperature-degree">34</h2>
<span>F</span>
<div class="temperature-description">Its cold</div>
</div>
<script src="app.js"></script>
</body>
</html>
42 changes: 42 additions & 0 deletions week-3/Homework/mandatory/1-practice/style.css
Original file line number Diff line number Diff line change
@@ -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;
}

18 changes: 11 additions & 7 deletions week-3/Homework/mandatory/2-exercises/exercise-1/exercise-1.js
Original file line number Diff line number Diff line change
@@ -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);
introduceYourself(name, age, favoriteFood);
18 changes: 18 additions & 0 deletions week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
29 changes: 20 additions & 9 deletions week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand All @@ -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
```


35 changes: 26 additions & 9 deletions week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.js
Original file line number Diff line number Diff line change
@@ -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}
]

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);