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

week-8 homework #1026

Open
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5502
}
9 changes: 6 additions & 3 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) {
fetch('https://codeyourfuture.herokuapp.com/api/greetings')
.then(function (response) {
return response.text();
})
.then(function(greeting) {
.then(function (greeting) {
let greetingText = document.getElementById("greeting-text")
greetingText.innerText = greeting

// Write the code to display the greeting text here
});
22 changes: 22 additions & 0 deletions week-8/Homework/mandatory/3-dog-photo-gallery/gallery.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="style.css" rel="stylesheet" />

<title>Document</title>

</head>

<body>

<button id="button"> press the Button</button>
<ul id="list">
</ul>
<div id="gallery"></div>
<script src="script.js"></script>
</body>

</html>
22 changes: 22 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,22 @@
let x = document.getElementById("gallery")
let clickedButton = document.getElementById("button")
let list = document.getElementById("list")
function fetchData() {
fetch('https://dog.ceo/api/breeds/image/random')
.then(function (response) {
return response.json();
})
.then(function (data) {
console.log(data);
showImg(data)
})
.catch((error) => console.log(error));
}
clickedButton.addEventListener("click", fetchData)
function showImg(data) {
let ul = document.createElement("li")
list.appendChild(ul)
let img1 = document.createElement("img")
ul.appendChild(img1)
img1.src = data.message
}
Empty file.
13 changes: 13 additions & 0 deletions week-8/Homework/mandatory/3-dog-photo-gallery/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,16 @@ Write a function that makes an API call to `https://dog.ceo/api/breeds/image/ran
- When the button is clicked it should make an API call to `https://dog.ceo/api/breeds/image/random`
- After receiving the data, append to the `<ul>` a `<li>` that contains an `<img>` element with the dog image
- Incorporate error handling













18 changes: 18 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,18 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="style.css" rel="stylesheet" />

<title>Document</title>
</head>

<body>

<div id="gallery"></div>
<script src="javascript.js"></script>
</body>

</html>
19 changes: 19 additions & 0 deletions week-8/Homework/mandatory/4-programmer-humour/javascript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
let gallery = document.getElementById("gallery")
fetchData()

function fetchData() {
fetch('https://xkcd.now.sh/?comic=latest')
.then(function (response) {
return response.json();
})
.then(function (data) {
console.log(data);
showImg(data)
})
.catch((error) => console.log(error));
}
function showImg(data) {
let img1 = document.createElement("img")
gallery.appendChild(img1)
img1.src = data.img
}