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

Js core3/week3/denis p #54

Open
wants to merge 8 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
11 changes: 10 additions & 1 deletion week-3/Homework/mandatory/1-practice/2-code-reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:

Expand All @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ 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}.`);
}

introduceYourself(personOne);
introduceYourself(personOne);
11 changes: 11 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,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}`) : '';
})
11 changes: 10 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,13 @@
{ itemName: "Hot Coffee", quantity: 2, unitPrice: 1.00},
{ itemName: "Hash Brown", quantity: 4, unitPrice: 0.40}
]


let totalPrice = 0;

console.log(`QTY ITEM TOTAL`);
order.forEach(({itemName, quantity, unitPrice}) => {
console.log(`${quantity} ${itemName} ${unitPrice}`);
totalPrice += unitPrice;
})

console.log(`Total: ${totalPrice}`);