Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Zision week 9.2 #1038

Open
wants to merge 2 commits into
base: manchester3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions week-8/Homework/mandatory/1-practice/1-practice.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ The following endpoint is publicly available from Github

<!-- Write your answer here -->

`{owner user id} {repo name} {pull request number}`

2. Describe in a sentence what this API endpoint returns when all of the fields are completed?

<!-- Write your answer here -->

Data stored in this endpoint.
17 changes: 10 additions & 7 deletions week-8/Homework/mandatory/2-fetch-exercise/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ Open index.html in your browser. Every time you refresh the page,
a different greeting should be displayed in the box.
*/

fetch('*** Write the API address here ***')
.then(function(response) {
return response.text();
})
.then(function(greeting) {
// Write the code to display the greeting text here
});
fetch("https://codeyourfuture.herokuapp.com/api/greetings")
.then(function (response) {
return response.text();
})
.then(function (greeting) {
// Write the code to display the greeting text here
let pEl = document.getElementById("greeting-text");
console.log(pEl);
pEl.innerText = greeting;
});
48 changes: 24 additions & 24 deletions week-8/Homework/mandatory/2-fetch-exercise/index.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<!doctype html>
<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8">
<title>CodeYourFuture - Fetch</title>
<meta name="description" content="Introduction to Fetch">
<meta name="author" content="CodeYourFuture">
<style>
#greeting-text {
font-size: 20px;
border: 1px solid #ccc;
background-color: #ddd;
width: 20%;
text-align: center;
margin: 0 50px;
padding: 30px;
}
</style>
</head>
<head>
<meta charset="utf-8" />
<title>CodeYourFuture - Fetch</title>
<meta name="description" content="Introduction to Fetch" />
<meta name="author" content="CodeYourFuture" />
<style>
#greeting-text {
font-size: 20px;
border: 1px solid #ccc;
background-color: #ddd;
width: 20%;
text-align: center;
margin: 0 50px;
padding: 30px;
}
</style>
</head>

<body>
<h1>A greeting in a random language...</h1>
<p id="greeting-text"></p>
<body>
<h1>A greeting in a random language...</h1>
<p id="greeting-text"></p>

<script src="exercise.js"></script>
</body>
</html>
<script src="exercise.js"></script>
</body>
</html>
13 changes: 13 additions & 0 deletions week-8/Homework/mandatory/3-dog-photo-gallery/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div id="container"></div>

<script src="script.js"></script>
</body>
</html>
32 changes: 32 additions & 0 deletions week-8/Homework/mandatory/3-dog-photo-gallery/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
let divEl = document.getElementById("container");

let buttonEl = document.createElement("button");
buttonEl.textContent = "Click Me";
let ulEl = document.createElement("ul");
let liEl = document.createElement("li");
let imgEl = document.createElement("img");

divEl.appendChild(buttonEl);
divEl.appendChild(ulEl);

ulEl.appendChild(liEl);
liEl.appendChild(imgEl);

function display() {
fetch("https://dog.ceo/api/breeds/image/random")
.then((response) => {
return response.json();
})
.then(function (data) {
console.log(data);
getImage(data);
});

function getImage(data) {
imgEl.src = data.message;
}
}

buttonEl.addEventListener("click", display);

window.onLoad = display();
12 changes: 12 additions & 0 deletions week-8/Homework/mandatory/4-programmer-humour/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div id="container"></div>
<script src="script.js"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions week-8/Homework/mandatory/4-programmer-humour/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
let divEl = document.getElementById("container");
let imgEl = document.createElement("img");
divEl.appendChild(imgEl);

fetch("https://xkcd.now.sh/?comic=latest")
.then((response) => {
return response.json();
})
.then((data) => {
console.log(data);
image(data);
});

function image(imageData) {
imgEl.src = imageData.img;
}
Empty file.
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,10 +10,18 @@ The output of running your code should be:
*/

class ShoppingCart {
// Add your code here
constructor() {
this.total = 0;
this.array = [];
}

addItem(item) {
this.array.push(item);
this.total++;

Choose a reason for hiding this comment

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

This works, but the code would be better if you only had one instance variable this.array and instead got the total from a function i.e.

total() {
  return this.array.length;
}

This is better because you don't have to keep track of two variables, you only need one.

}

cartContains() {
// Use console.log() to output everything contained in your cart
console.log(`Your shopping cart has ${this.total} items : ${this.array} `);

Choose a reason for hiding this comment

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

To make the output easier to read you can do this instead:

${this.array.join(', ')}

}
}

Expand Down
10 changes: 8 additions & 2 deletions week-9/Homework/mandatory/2-exercises/2-convertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@


*/

// Write your code here
class Person {
constructor(name) {
this.name = name;
}
greeting() {
console.log(`I am ${this.name}.`);
}
}

// Do not edit this section
const simon = new Person("simon");
Expand Down
22 changes: 19 additions & 3 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,24 @@
*/

class ATM {
// Add your code here

constructor() {
this.amount = 100.0;
}
make_deposit(num) {
this.amount += num;
}
make_withdrawl(num) {
if (this.amount - num > 0) {
this.amount -= num;
} else {
console.log(
"Sorry you don't have enough balance to withdrawl this amount!"
);
}
}
check_balance() {
console.log(this.amount);
}
}

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