diff --git a/week-8/Homework/mandatory/1-practice/1-practice.md b/week-8/Homework/mandatory/1-practice/1-practice.md index 02aa34989..325b930a2 100644 --- a/week-8/Homework/mandatory/1-practice/1-practice.md +++ b/week-8/Homework/mandatory/1-practice/1-practice.md @@ -26,6 +26,10 @@ The following endpoint is publicly available from Github +`{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? + +Data stored in this endpoint. diff --git a/week-8/Homework/mandatory/2-fetch-exercise/exercise.js b/week-8/Homework/mandatory/2-fetch-exercise/exercise.js index fb3a39c2a..52e8f82ea 100644 --- a/week-8/Homework/mandatory/2-fetch-exercise/exercise.js +++ b/week-8/Homework/mandatory/2-fetch-exercise/exercise.js @@ -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 - }); \ No newline at end of file +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; + }); diff --git a/week-8/Homework/mandatory/2-fetch-exercise/index.html b/week-8/Homework/mandatory/2-fetch-exercise/index.html index e3c9aa43c..923296047 100644 --- a/week-8/Homework/mandatory/2-fetch-exercise/index.html +++ b/week-8/Homework/mandatory/2-fetch-exercise/index.html @@ -1,28 +1,28 @@ - + - - - CodeYourFuture - Fetch - - - - + + + CodeYourFuture - Fetch + + + + - -

A greeting in a random language...

-

+ +

A greeting in a random language...

+

- - - \ No newline at end of file + + + diff --git a/week-8/Homework/mandatory/3-dog-photo-gallery/index.html b/week-8/Homework/mandatory/3-dog-photo-gallery/index.html new file mode 100644 index 000000000..ecbbe3617 --- /dev/null +++ b/week-8/Homework/mandatory/3-dog-photo-gallery/index.html @@ -0,0 +1,13 @@ + + + + + + Document + + +
+ + + + diff --git a/week-8/Homework/mandatory/3-dog-photo-gallery/script.js b/week-8/Homework/mandatory/3-dog-photo-gallery/script.js new file mode 100644 index 000000000..9492d65ad --- /dev/null +++ b/week-8/Homework/mandatory/3-dog-photo-gallery/script.js @@ -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(); diff --git a/week-8/Homework/mandatory/4-programmer-humour/index.html b/week-8/Homework/mandatory/4-programmer-humour/index.html new file mode 100644 index 000000000..9860cc230 --- /dev/null +++ b/week-8/Homework/mandatory/4-programmer-humour/index.html @@ -0,0 +1,12 @@ + + + + + + Document + + +
+ + + diff --git a/week-8/Homework/mandatory/4-programmer-humour/script.js b/week-8/Homework/mandatory/4-programmer-humour/script.js new file mode 100644 index 000000000..16347a340 --- /dev/null +++ b/week-8/Homework/mandatory/4-programmer-humour/script.js @@ -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; +} diff --git a/week-8/Homework/mandatory/4-programmer-humour/style.css b/week-8/Homework/mandatory/4-programmer-humour/style.css new file mode 100644 index 000000000..e69de29bb diff --git a/week-9/Homework/mandatory/2-exercises/1-shopping-cart.js b/week-9/Homework/mandatory/2-exercises/1-shopping-cart.js index d58a05143..9773ce27a 100644 --- a/week-9/Homework/mandatory/2-exercises/1-shopping-cart.js +++ b/week-9/Homework/mandatory/2-exercises/1-shopping-cart.js @@ -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++; + } cartContains() { - // Use console.log() to output everything contained in your cart + console.log(`Your shopping cart has ${this.total} items : ${this.array} `); } } diff --git a/week-9/Homework/mandatory/2-exercises/2-convertion.js b/week-9/Homework/mandatory/2-exercises/2-convertion.js index d70ca4fcd..2838f75cb 100644 --- a/week-9/Homework/mandatory/2-exercises/2-convertion.js +++ b/week-9/Homework/mandatory/2-exercises/2-convertion.js @@ -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"); diff --git a/week-9/Homework/mandatory/2-exercises/3-atm.js b/week-9/Homework/mandatory/2-exercises/3-atm.js index 768bce40e..cc508a1f4 100644 --- a/week-9/Homework/mandatory/2-exercises/3-atm.js +++ b/week-9/Homework/mandatory/2-exercises/3-atm.js @@ -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 @@ -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 \ No newline at end of file +atm.make_withdrawl(500); // Your ATM should be able to handle this scenario