From 1185c57ff3c5fda0841da8bf7c2099c996b9591a Mon Sep 17 00:00:00 2001 From: zision Date: Thu, 16 Jul 2020 22:58:03 +0100 Subject: [PATCH] HW submission from new repo. --- .../mandatory/1-practice/1-practice.md | 4 ++ .../mandatory/2-fetch-exercise/exercise.js | 17 ++++--- .../mandatory/2-fetch-exercise/index.html | 48 +++++++++---------- .../mandatory/3-dog-photo-gallery/index.html | 13 +++++ .../mandatory/3-dog-photo-gallery/script.js | 32 +++++++++++++ .../mandatory/4-programmer-humour/index.html | 12 +++++ .../mandatory/4-programmer-humour/script.js | 16 +++++++ .../mandatory/4-programmer-humour/style.css | 0 8 files changed, 111 insertions(+), 31 deletions(-) create mode 100644 week-8/Homework/mandatory/3-dog-photo-gallery/index.html create mode 100644 week-8/Homework/mandatory/3-dog-photo-gallery/script.js create mode 100644 week-8/Homework/mandatory/4-programmer-humour/index.html create mode 100644 week-8/Homework/mandatory/4-programmer-humour/script.js create mode 100644 week-8/Homework/mandatory/4-programmer-humour/style.css 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