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

finished week 3 #50

Open
wants to merge 1 commit 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
7 changes: 7 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.
- because line 4 statement uses variable from line 3, and line 6 statement uses the variable from line 1

## Question 2

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

What will be the output of this code. Explain your answer in 50 words or less.
- first console.log statement will print 10
- second console statement will call the function which will print 10 again, then "undefined" will be printed because the return value of f1() is undefined
- third statement will cause an error because y is not in the same scope

## Question 3

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

What will be the output of this code. Explain your answer in 50 words or less.
- first console.log will print 9 (f1() does nothing to x because it copies the variable)
- second console.log statement will print { x: 10 } because the object y is first created and then the variable y is modified with f2() function, since the function modifies original object, not it's copy.
const allows the modification of the object attributes, but it does not allow the var y to be reassigned to another object.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const personOne = {
favouriteFood: 'Spinach'
}

let {name, age, favouriteFood} = personOne;

function introduceYourself(___________________________) {
console.log (`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`);
}
Expand Down
24 changes: 23 additions & 1 deletion week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,26 @@ let hogwarts = [
{ 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 displayNames(arr) {
for(var i = 0; i < arr.length; ++i) {
if (arr[i].house === "Gryffindor") {
let { firstName, lastName } = arr[i];
console.log(`${firstName} ${lastName}`);
}}
}

displayNames(hogwarts);

console.log("");

function displayNames_v2(arr) {
for(var i = 0; i < arr.length; ++i) {
if (arr[i].pet !== null && arr[i].occupation === "Teacher") {
let { firstName, lastName } = arr[i];
console.log(`${firstName} ${lastName}`);
}}
}

displayNames_v2(hogwarts);
18 changes: 17 additions & 1 deletion week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,20 @@
{ itemName: "Hot Coffee", quantity: 2, unitPrice: 1.00},
{ itemName: "Hash Brown", quantity: 4, unitPrice: 0.40}
]


function printOrder(order) {
let totalPrice = 0;
console.log(`QTY\tITEM\t\t\tTOTAL`)
for(let i = 0; i < order.length; ++i) {
let {itemName, quantity, unitPrice} = order[i];
totalPrice += unitPrice;

if(itemName.length > 12)
console.log(`${quantity}\t${itemName}\t${unitPrice.toFixed(2)}`);
else
console.log(`${quantity}\t${itemName}\t\t${unitPrice.toFixed(2)}`);
}
console.log(`\nTotal: ${totalPrice.toFixed(2)}`);
}

printOrder(order);