Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Almost done.
  • Loading branch information
GTabala committed Sep 13, 2020
commit 711a06afffce9ed9ef37a310c38e3fd32fdf7341
14 changes: 14 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.
On line 6, x is a global variable. On line 4, x is a local variable whose scope is within a block of lines 2 through 5.

## Question 2

Expand All @@ -33,6 +34,10 @@ console.log(y)
```

What will be the output of this code. Explain your answer in 50 words or less.
There will be:
10 - x is a global variable. (line 28)
undefined - the function f1 doesn't return any value. (line 32)
error - variable y is not defined - variable y has a scope only within the function f1. (line 33)

## Question 3

Expand Down Expand Up @@ -61,3 +66,12 @@ console.log(y);
```

What will be the output of this code. Explain your answer in 50 words or less.

On line 47 defines a global constant x with value 9.
On line 54 calls function f1, but the result doesn't set to any variable.
Function f1 gets the value of constant x as a parameter and doesn't change it (and even can't).
On line 55 the result will be 9.
On line 57 defines a global constant and sets to object.
On line 64 calls function f2, but the result doesn't set to any variable.
Nevertheless, function f2 gets an object y as a parameter and change its property.
On line 65 the result will be {x: 10}.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const personOne = {
favouriteFood: 'Spinach'
}

function introduceYourself(___________________________) {
function introduceYourself(anyPerson) {
let {name, age, favouriteFood} = anyPerson;
console.log (`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`);
}

Expand Down
10 changes: 10 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,13 @@ let hogwarts = [
{ firstName: "Minerva", lastName: "McGonagall", house: "Gryffindor", pet: null, occupation: "Teacher" },
{ firstName: "Albus", lastName: "Dumbledore", house: "Gryffindor", pet: "Phoenix", occupation: "Teacher" }
]

hogwarts.filter(person => person.house === "Gryffindor").forEach(person =>{
let {firstName, lastName} = person;
console.log(`${firstName} ${lastName}`);
});
console.log(" ");
hogwarts.filter(person => person.occupation === "Teacher" && person.pet).forEach(person =>{
let {firstName, lastName} = person;
console.log(`${firstName} ${lastName}`);
});
37 changes: 28 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,28 @@
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 },
];

function getSpaces(words, length) {
while (("" + words).length < length) {
words += " ";
}
return words;
}

console.log(getSpaces("QTY", 8) + getSpaces("ITEM", 20) + "TOTAL");
let total = 0;
order.forEach((item) => {
let { itemName, quantity, unitPrice } = item;
let sum = quantity * unitPrice;
total += sum;
console.log(
getSpaces(quantity, 8) + getSpaces(itemName, 20) + sum.toFixed(2)
);
});
console.log("");
console.log("Total: " + total.toFixed(2));