-
-
Notifications
You must be signed in to change notification settings - Fork 455
Leida week 9 #1030
base: master
Are you sure you want to change the base?
Leida week 9 #1030
Conversation
to follow previously sent common practice and instructions fixed some typos
Minor changes to make language consistent and simplify it where needed.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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 }); |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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 ${ |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 ${ |
There was a problem hiding this comment.
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
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