Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Leida week 9 #1030

Open
wants to merge 58 commits into
base: master
Choose a base branch
from
Open

Conversation

Leidagandy
Copy link

Your Details

Your Name: Leida Goncalves
Your City: Manchester
Your Slack Name: Leida Gandy

Homework Details

Module: JS III Week 9
Week: JS III Week 9

Copy link

@lannem lannem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done Leida, really good work and you I see you trying to get your code as tidy and efficient as possible 💯

@@ -47,7 +51,7 @@ function f1(val) {
}

f1(x);
console.log(x);
console.log(x); (I am not sure why it outputs 9)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It outputs 9 because nothing happens to x after it is declared on line 46, the f1() function is called but that only adds 1 to variable val which is declared inside the function.

f1(x) would return 10 but that is not what is being logged to the console :)

@@ -14,6 +14,8 @@ Take a look at the following code:
```

Explain why line 4 and line 6 output different numbers.
// In line 1 a global variable is declared and assigned the value of 1, it will be available everywhere in the application.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent explanation for this question well done!

What will be the output of this code. Explain your answer in 50 words or less.
What will be the output of this code.// Explain your answer in 50 words or less.
Line 30 will print 10 to the console because x is a global variable.
Line 34 will print y is not defined, this is because y is a local variable only accessible inside the functiion. So this x it is out of scope for the console.log called on line 6. The function itself should return undefined.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct! (I am not sure what you are referring to on line 6 however, I think you might have a typo)

@@ -57,7 +61,7 @@ function f2(val) {
}

f2(y);
console.log(y);
console.log(y);// Returns 10. y is a parameter of function f2, it was declared and initialised with the value of 9 (line 56). Function f2 added 1 to x property and this updated y to 10 because why is equal to the value of the x property.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct!

this.cart.push(item);
}
listItems() {
this.cart.forEach((item) => console.log(item));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of an arrow function and forEach here :)

this.index = 0;
}
add(title, artist) {
this.playlist.push({ title, artist });
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent 💯

this.playlist.push({ title, artist });
}

play() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great 👍

this.index++;
if (this.index <= this.playlist.length - 1) {
console.log(
`Currently playing: ${this.playlist[this.index].title} by ${
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you already have a function that does this, you could call your play function instead of typing out the whole console log again


skip() {
this.index++;
if (this.index <= this.playlist.length - 1) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good but what happens if this is not true?

previous() {
this.index -= 1;
console.log(
`Currently playing: ${this.playlist[this.index].title} by ${
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, just think about re-using your play function again as I mentioned above

@lannem lannem added the reviewed A mentor has reviewed this PR label Jul 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
reviewed A mentor has reviewed this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants