Conversation
| ``` | ||
|
|
||
| Explain why line 4 and line 6 output different numbers. | ||
| Because line 4 will print Local variable (which x is defined again) which is 2 but line 6 will print global variable which is 1 |
| ``` | ||
|
|
||
| What will be the output of this code. Explain your answer in 50 words or less. | ||
| line 32 print 10 and undefined because line 28 print 10 and y will return as undefined ,line 33 dosen't print anything because y is not defined globally. |
There was a problem hiding this comment.
Line 32 will print undefined not because of y variable but because f1 function doesn't return anything. Line 33 will print a Reference Error because as you wrote, y not is defined globally
| ``` | ||
|
|
||
| What will be the output of this code. Explain your answer in 50 words or less. | ||
| 9 and {x:10} because in line 50 it console.log (x) which is 9 and in line 60 it console.log(y) which is {x:9} |
There was a problem hiding this comment.
Correct, and this is because f1 and f2 functions don't modify x and y variables in the global scope
| return response.json(); | ||
| }) | ||
| .then((data) => { | ||
| console.log(data); |
There was a problem hiding this comment.
Remember to delete console logs (line 12 and 22) before committing
| setIcon(icon, document.querySelector(".icon")); | ||
|
|
||
| //change tempreture to celsius/farenheit | ||
| tempretureSection.addEventListener("click", () => { |
There was a problem hiding this comment.
Well done! All works fine🙂 I would encourage you to always try to write a clean code - break the logic down into smaller functions and call them where needed.
| if (amount > 0) { | ||
| this.balance += amount; | ||
| } else { | ||
| console.log(`Please enter a positive number`); |
| console.log(`You have ${this.balance} in your account`); | ||
| } | ||
| make_withdrawl(amount) { | ||
| if (this.balance > amount && amount > 0) { |
There was a problem hiding this comment.
Good error handling again - it shows that you think about what could go wrong
| // Add your code here | ||
|
|
||
| constructor() { | ||
| this.i = 0; |
There was a problem hiding this comment.
i could be something more meaningful here
| } | ||
|
|
||
| shuffle() { | ||
| let random = Math.floor(Math.random() * this.playList.length); |
There was a problem hiding this comment.
How would you make sure that the song won't be repeated when shuffle is called multiple times in a row?
| this.i++; | ||
| this.play(); | ||
| } else { | ||
| console.log(`There isn't any song to play`); |
There was a problem hiding this comment.
I think it's fine to console log that there are no more songs to play, but another solution could be to start playing songs from the beginning
Your Details
Your Name:
Your City:
Your Slack Name:
Homework Details
Module:
Week: