-
-
Notifications
You must be signed in to change notification settings - Fork 458
Hedyeh week 9 #1031
base: manchester3
Are you sure you want to change the base?
Hedyeh week 9 #1031
Conversation
@@ -14,6 +14,7 @@ Take a look at the following code: | |||
``` | |||
|
|||
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 |
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 ✅
@@ -33,6 +34,7 @@ console.log(y) | |||
``` | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -61,3 +63,4 @@ console.log(y); | |||
``` | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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`); |
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.
I like the error handling here👏
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i
could be something more meaningful here
} | ||
|
||
shuffle() { | ||
let random = Math.floor(Math.random() * this.playList.length); |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: