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

Shahd week 8 #1003

Closed
Closed
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
6 changes: 4 additions & 2 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,12 @@ 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 ***')
fetch("https://codeyourfuture.herokuapp.com/api/greetings")
Copy link
Member

Choose a reason for hiding this comment

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

Yep, works well!

.then(function(response) {
return response.text();
})
.then(function(greeting) {
// Write the code to display the greeting text here
let box = document.getElementById("greeting-text");
box.innerText = greeting;
// console.log(greeting) // Write the code to display the greeting text here
});
17 changes: 17 additions & 0 deletions week-8/Homework/mandatory/3-dog-photo-gallery/dogPhotos.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dog Photos fetch practice</title>
</head>
<body>
<div id ="wrapper">
<ul id="saver">

</ul>
<button id="click">Next photo ></button>
</div>
<script src="dogPhotos.js"></script>
</body>
</html>
22 changes: 22 additions & 0 deletions week-8/Homework/mandatory/3-dog-photo-gallery/dogPhotos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

const ul = document.getElementById("saver");
const btn = document.getElementById("click");
const li = document.createElement("li");
const myImg = document.createElement("img");

function displayer(){
Copy link
Member

Choose a reason for hiding this comment

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

Works well!

fetch("https://dog.ceo/api/breeds/image/random")
.then(response => response.json())
.then(data => data.message)
.then(function (img){
Copy link
Member

Choose a reason for hiding this comment

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

Try to stick to the same function format (e.g. arrow functions) for consistency.

li.appendChild(myImg);
li.style.listStyleType = "none"
ul.appendChild(li);
myImg.src = img;
})
.catch(err => console.error(err));
Copy link
Member

Choose a reason for hiding this comment

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

How about error handling? Could you do something more than just console.log it?

}

btn.addEventListener("click",displayer)
window.onload = displayer;

Empty file.
15 changes: 15 additions & 0 deletions week-8/Homework/mandatory/4-programmer-humour/humour.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="humour.css" />
</head>
<body>
<div id="container">

</div>
<script src="humour.js"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions week-8/Homework/mandatory/4-programmer-humour/humour.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const div = document.getElementById("container");
const img = document.createElement("img");

function fether(){
Copy link
Member

Choose a reason for hiding this comment

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

Works well!

fetch("https://xkcd.now.sh/?comic=latest")
.then(response => response.json())
.then(function (data) {
let myData = data.img;
console.log(myData);
div.appendChild(img);
img.src = myData;
})
.catch(anyErr => console.error(anyErr));
Copy link
Member

Choose a reason for hiding this comment

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

Again, think about error handling. What could you display to the user?

}

window.onload = fether;