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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
d0eb2ef
added notes to w2-j4
Ashaghel Apr 26, 2020
c30ee0f
Hakona Matata Anthony and Ahmad
Ashaghel Apr 26, 2020
74e3f46
fix minor spelling and grammatical errors
Apr 27, 2020
6fcaeb5
editing exercises for week3 mcr3
Ashaghel May 1, 2020
468db41
Update 5-journey-planner.js
Ashaghel May 2, 2020
6163944
Update 0- Introduction.md
Ashaghel May 2, 2020
9346bcb
added info on every and some to exercise 2
Augs0 May 2, 2020
960c002
fixed formatting
Augs0 May 2, 2020
c5786a9
added info on replace and substring
Augs0 May 2, 2020
eb54bc5
Modify description and add extra tests to exercise week-3/4-eligible-…
zoltan-gal May 2, 2020
191b122
fix syntax
zoltan-gal May 2, 2020
e20bef6
Add extra exercise to week-3/4-eligible-students
zoltan-gal May 2, 2020
7905332
added small note
Ashaghel May 2, 2020
6c489f4
Added more instructions
Ashaghel May 2, 2020
ce4cdb0
changed function name
Ashaghel May 2, 2020
46747c0
Update 6-lane-names.js
Ashaghel May 2, 2020
1422133
formating
Ashaghel May 2, 2020
4feab6b
Add more details and restructure journey planner exercise
zoltan-gal May 2, 2020
349fee5
Reformatting journey planner description
zoltan-gal May 2, 2020
fe6726a
Add extra challange tip to journey planner
zoltan-gal May 2, 2020
9678006
Add examples and tweak descriptions
zoltan-gal May 2, 2020
222a34b
tweak week-3 intro description
zoltan-gal May 2, 2020
ccc11b5
tweak week-3 intro description
zoltan-gal May 2, 2020
7a91d2e
fix text
zoltan-gal May 2, 2020
1a7abaf
Improve examples in ex4
zoltan-gal May 2, 2020
e84f22f
Merge remote-tracking branch 'origin/master' into manchester3
zoltan-gal May 15, 2020
f8f41b0
more info
Ashaghel May 16, 2020
68f6d79
Create forinLoop.js
Ashaghel May 16, 2020
57dc8b0
Select freecodecamp resource list
zoltan-gal May 16, 2020
891b2aa
Add extra exercise and description to writers exercise
zoltan-gal May 16, 2020
e50722e
Add extra exercises to water bottle exercise
zoltan-gal May 16, 2020
02492c9
Remove extra resources recommendations that have not been taught yet
zoltan-gal May 16, 2020
394aab1
Merge branch 'manchester3' of github.com:CodeYourFuture/js-exercises …
zoltan-gal May 16, 2020
1feffbe
Rewrite grocery list exercise
zoltan-gal May 16, 2020
4a1fa48
Fix week-4 exercise issues
zoltan-gal May 16, 2020
a3c1d0c
more reading
Ashaghel May 16, 2020
393cab1
Update 1-freecodecamp.md
Ashaghel May 16, 2020
05218bc
Update extra-homework.md
Ashaghel May 16, 2020
f836b89
Update 1-freecodecamp.md
Ashaghel May 16, 2020
90f6f0b
Update 1-freecodecamp.md
Ashaghel May 16, 2020
a4055ca
Update 1-freecodecamp.md
Ashaghel May 16, 2020
e559c9a
Update 2-writers.js
Ashaghel May 16, 2020
9b87a3e
fix description
zoltan-gal May 17, 2020
793cd96
tweak description
zoltan-gal May 17, 2020
1d25f8e
Update 2-writers.js
May 19, 2020
55efde1
fix wording
zoltan-gal May 20, 2020
27ce362
Rewrite week-5/2-exercises
zoltan-gal May 29, 2020
f555e27
Rewrite week-5/3-project
zoltan-gal May 29, 2020
6053f8e
tweak khanakademy hw descriptions
zoltan-gal May 29, 2020
37bc38e
add extra description to week-5, exercise 3
zoltan-gal May 30, 2020
6409675
fix link
zoltan-gal May 31, 2020
b92dcd4
Merge remote-tracking branch 'origin/master' into manchester3
zoltan-gal Jun 6, 2020
ff6e285
Update week-6 exercise description
zoltan-gal Jun 6, 2020
4f47071
Update week-8 homework description
dsobkow Jun 26, 2020
c3e951a
Update project instructions
dsobkow Jun 27, 2020
4ba7878
Update 2-convertion.js
Ashaghel Jul 4, 2020
e15d669
Update 4-music-player.js
Ashaghel Jul 4, 2020
c9ad0b2
Leida's week 9 homework
Leidagandy Jul 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions week-9/Homework/mandatory/1-practice/2-code-reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

// In line 3 a new local variable is declared and assigned the value of 2. This a new variable which happens to have the same name, x. It will be available only inside this function. They are different variables with different values.

## Question 2

Expand All @@ -32,7 +34,9 @@ console.log(f1())
console.log(y)
```

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)


## Question 3

Expand All @@ -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 :)


const y = { x: 9 };

Expand All @@ -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!

```

What will be the output of this code. Explain your answer in 50 words or less.
45 changes: 45 additions & 0 deletions week-9/Homework/mandatory/1-practice/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
window.addEventListener("load", () => {
let lon;
let lat;
let temperatureDescription = document.querySelector(
".temperature-description"
);
let temperatureDegree = document.querySelector(".temperature-degree");
let locationTimezone = document.querySelector(".location-timezone");
let temperatureSection = document.querySelector(".temperature");
let temperatureSpan = document.querySelector(".temperature span");

if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
console.log(position);
lon = position.coords.longitude;
lat = position.coords.latitude;

const api = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=529112615b6aef3609d4abccfeb0e297&units=metric`;
fetch(api)
.then((response) => {
return response.json();
})
.then((data) => {
const temperature = data.main.temp;
const summary = data.weather[0].description;
//Set DOM elements from the API
temperatureDegree.textContent = temperature;
temperatureDescription.textContent = summary;
locationTimezone.textContent = data.name;
//formula for Farenheit
let farenheit = temperature * (9 / 5) + 32;
//change temperature from Celsius to Farenheit
temperatureSection.addEventListener("click", () => {
if (temperatureSpan.textContent === "C") {
temperatureDegree.textContent = farenheit.toFixed(2);
temperatureSpan.textContent = "F";
} else {
temperatureDegree.textContent = temperature;
temperatureSpan.textContent = "C";
}
});
});
});
}
});
24 changes: 24 additions & 0 deletions week-9/Homework/mandatory/1-practice/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Weather</title>
</head>
<body>
<div class="location">
<h1 class="location-timezone">Timezone</h1>
<p id="icon">Icon</p>
</div>
<div class="temperature">
<div class="degree-section">
<h2 class="temperature-degree">34</h2>
<span>C</span>
</div>
<div class="temperature-description">It is freezing cold</div>
</div>

<script src="app.js"></script>
</body>
</html>
38 changes: 38 additions & 0 deletions week-9/Homework/mandatory/1-practice/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
height: 100vh;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
background: linear-gradient(rgb(47, 150, 163), rgb(48, 62, 143));
font-family: sans-serif;
color: white;
}
.location,
.temperature {
height: 30vh;
width: 50%;
display: flex;
justify-content: space-around;
align-items: center;
}
.temperature {
flex-direction: column;
}
.degree-section {
display: flex;
align-items: center;
cursor: pointer;
}
degree-section span {
margin: 10px;
font-size: 30px;
}
.degree-section h2 {
font-size: 40px;
}
12 changes: 10 additions & 2 deletions week-9/Homework/mandatory/2-exercises/1-shopping-cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ The output of running your code should be:
*/

class ShoppingCart {
// Add your code here

constructor() {
this.cart = [];
}
addItem(item) {
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 :)

}
cartContains() {
console.log(this.cart);
Copy link

Choose a reason for hiding this comment

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

You are very close with this one but you are missing some things from your console log, have another look at what the question says the output should be.

Great job!

// Use console.log() to output everything contained in your cart
}
}
Expand Down
9 changes: 9 additions & 0 deletions week-9/Homework/mandatory/2-exercises/2-convertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
*/

// Write your code here
class Person {
constructor(personName) {
this.name = personName;
}

greeting() {
console.log("Hi I am " + this.name + ".");
}
}
Copy link

Choose a reason for hiding this comment

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

Perfect! Nice and simple code well done 🥇


// Do not edit this section
const simon = new Person("simon");
Expand Down
23 changes: 21 additions & 2 deletions week-9/Homework/mandatory/2-exercises/3-atm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,27 @@
*/

class ATM {
// Add your code here
constructor() {
this.balance = 100;
}

make_deposit(money) {
this.balance += money;
}

check_balance() {
this.balance;
Copy link

Choose a reason for hiding this comment

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

You are so close! You just missed a return statement

}

make_withdrawl(money) {
if (this.balance >= money) {
this.balance -= money;
} else {
`you dont have enough funds, try a smaller amount`;
Copy link

Choose a reason for hiding this comment

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

Missed that return statement again :)

}

// Add your code here
}
}

let atm = new ATM(); // Create the ATM
Expand All @@ -22,4 +41,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
Copy link

Choose a reason for hiding this comment

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

Well done on handling this! Really good job on this exercise

72 changes: 49 additions & 23 deletions week-9/Homework/mandatory/2-exercises/4-music-player.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*


Task 1: Complete the below code to create a music player that will run through a playlist of songs and output to the console as described in the comments.
Task 1: Complete the below code to create a music player that will run through
a playlist of songs and output to the console as described in the comments.

Task 2: Add some extra logic to handle these 2 scenarios:
- Trying to call myMusicPlayer.play() if there are no songs in the playlist
Expand All @@ -18,36 +19,61 @@ This means the order the songs are played in will be random, but each song will

*/


class MusicPlayer {
// Add your code here

constructor() {
this.playlist = [];
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 💯

}

play() {
Copy link

Choose a reason for hiding this comment

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

great 👍

if (this.playlist.length === 0) {
console.log("Your playlist is empty. Add new songs!");
} else {
console.log(
`Currently playing: ${this.playlist[this.index].title} by ${
this.playlist[this.index].artist
}`
);
}
}

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?

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

this.playlist[this.index].artist
}`
);
}
}

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

this.playlist[this.index].artist
}`
);
}
}

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"






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"