-
-
Notifications
You must be signed in to change notification settings - Fork 458
Iman week 9 #1023
base: manchester3
Are you sure you want to change the base?
Iman week 9 #1023
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,10 @@ Take a look at the following code: | |
|
||
Explain why line 4 and line 6 output different numbers. | ||
|
||
line 6 log first variable, the first variable is global variable and can be use evrywhere in code, | ||
but om line 4 the second variable been logged which is local variable. | ||
means it's just been defined inside the square bracets. | ||
|
||
## Question 2 | ||
|
||
Take a look at the following code: | ||
|
@@ -34,6 +38,9 @@ console.log(y) | |
|
||
What will be the output of this code. Explain your answer in 50 words or less. | ||
|
||
the first log's output is 10, it's been defined globally and used inside the function. | ||
the second log's output is not defined because it tries to log a local variable outside the function. | ||
|
||
## Question 3 | ||
|
||
Take a look at the following code: | ||
|
@@ -61,3 +68,5 @@ console.log(y); | |
``` | ||
|
||
What will be the output of this code. Explain your answer in 50 words or less. | ||
first console.log output is 9, | ||
second console.log is an object: x: 9 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one is a bit tricky, search passing by value vs passing by reference |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,15 @@ The output of running your code should be: | |
|
||
class ShoppingCart { | ||
// Add your code here | ||
|
||
constructor() { | ||
this.myBasket = []; | ||
} | ||
addItem(item) { | ||
this.myBasket.push(item); | ||
} | ||
cartContains() { | ||
// Use console.log() to output everything contained in your cart | ||
console.log(this.myBasket); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perfect |
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,29 @@ | |
*/ | ||
|
||
class ATM { | ||
// Add your code here | ||
|
||
// Add your code here | ||
constructor(amount) { | ||
this.amount = amount; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is a small issue here, your constructure require an argument, but when you created an instance of the class in line 19 you didn't pass it. |
||
this.balance = 100; | ||
} | ||
|
||
make_deposit(amount) { | ||
this.balance += amount; | ||
console.log(`Your New Balance Is ${this.balance}`); | ||
} | ||
|
||
check_balance() { | ||
console.log(`Your Balance Is ${this.balance}`); | ||
} | ||
|
||
make_withdrawl(amount) { | ||
if (amount > this.balance || amount < 0) { | ||
console.log(`Sorry You Dont Have Enough Money In Your Account`); | ||
} else { | ||
this.balance -= amount; | ||
console.log(`Your New Balance Is ${this.balance}`); | ||
} | ||
} | ||
} | ||
|
||
let atm = new ATM(); // Create the ATM | ||
|
@@ -22,4 +43,4 @@ atm.make_deposit(200); | |
atm.check_balance(); | ||
atm.make_withdrawl(100); | ||
|
||
atm.make_withdrawl(500); // Your ATM should be able to handle this scenario | ||
atm.make_withdrawl(500); // Your ATM should be able to handle this scenario |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,36 +18,55 @@ This means the order the songs are played in will be random, but each song will | |
|
||
*/ | ||
|
||
|
||
class MusicPlayer { | ||
// Add your code here | ||
|
||
// Add your code here | ||
constructor() { | ||
this.playList = []; | ||
this.i = 0; | ||
} | ||
add(song, singer) { | ||
this.playList.push(`${song} by ${singer}`); | ||
} | ||
play() { | ||
if (this.playList.length == 0) { | ||
this.playList[this.i] = "There Is No Song To Play"; | ||
} else { | ||
console.log(`Currently playing: ` + this.playList[this.i]); | ||
} | ||
} | ||
skip() { | ||
this.i += 1; | ||
if (this.i == this.playList.length) { | ||
this.i = 0; | ||
} else if (this.playList.length == 0) { | ||
this.playList[this.i] = "There Is No Song To Play"; | ||
} | ||
console.log(`Currently playing: ` + this.playList[this.i]); | ||
} | ||
previous() { | ||
this.i -= 1; | ||
if (this.i < 0) { | ||
this.i = this.playList.length - 1; | ||
} else if (this.playList.length == 0) { | ||
this.playList[this.i] = "There Is No Song To Play"; | ||
} | ||
console.log(`Currently playing: ` + this.playList[this.i]); | ||
} | ||
} | ||
|
||
let myMusicPlayer = new MusicPlayer(); // Create an empty playlist | ||
|
||
// Add some songs to your playlist | ||
myMusicPlayer.add("Bohemian Rhapsody","Queen"); | ||
myMusicPlayer.add("Yesterday","The Beatles"); | ||
myMusicPlayer.add("Vogue","Madonna"); | ||
|
||
myMusicPlayer.play(); // Output: "Currently playing: Bohemian Rhapsody by Queen" | ||
|
||
myMusicPlayer.skip(); // Output: "Currently playing: Yesterday by The Beatles" | ||
|
||
myMusicPlayer.previous(); // Output: "Currently playing: Bohemian Rhapsody by Queen" | ||
|
||
myMusicPlayer.skip(); // Output: "Currently playing: Yesterday by The Beatles" | ||
|
||
myMusicPlayer.skip(); // Output: "Currently playing: Vogue by Madonna" | ||
|
||
|
||
|
||
|
||
|
||
|
||
//Add some songs to your playlist | ||
myMusicPlayer.add("Bohemian Rhapsody", "Queen"); | ||
myMusicPlayer.add("Yesterday", "The Beatles"); | ||
myMusicPlayer.add("Vogue", "Madonna"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent work! |
||
|
||
myMusicPlayer.play(); //Output: "Currently playing: Bohemian Rhapsody by Queen"; | ||
|
||
myMusicPlayer.skip(); // Output: "Currently playing: Yesterday by The Beatles" | ||
|
||
myMusicPlayer.previous(); // Output: "Currently playing: Bohemian Rhapsody by Queen" | ||
|
||
myMusicPlayer.skip(); // Output: "Currently playing: Yesterday by The Beatles" | ||
|
||
myMusicPlayer.skip(); // Output: "Currently playing: Vogue by Madonna" |
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 changed the PR to be against Manchester3 branch instead of master, ensure to check this as it may cause problems if people started adding comments :)