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

Altom week-8 #1006

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": 5501
}
26 changes: 18 additions & 8 deletions week-8/Homework/mandatory/2-fetch-exercise/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Response: A greeting in a random language
To learn more about fetch, refer to the doc:
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch


================
Expected result
================
Expand All @@ -17,10 +16,21 @@ 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) {
greetingWords(greeting);
console.log(greeting);

// Write the code to display the greeting text here
});

let getHtmlDoc = document.getElementById("greeting-text");

function greetingWords(greet) {
let createH2 = document.createElement("H2");
createH2.textContent = greet;
getHtmlDoc.appendChild(createH2);
}
Copy link

@Abdoulrazack95 Abdoulrazack95 Jul 2, 2020

Choose a reason for hiding this comment

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

You got wrong here, the random greeting should be displayed in the box not to display it in a h2 and you don't have .catch if there is an error. It needs to be fixed.

30 changes: 30 additions & 0 deletions week-8/Homework/mandatory/3-dog-photo-gallery/exercise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
let getBtn = document.getElementById("random-image");
function getData() {
fetch("https://dog.ceo/api/breeds/image/random")
.then((response) => {
return response.json();
})
.then((data) => {
let printImg = data.message;
myImages(printImg);
console.log(data);
})
.catch((error) => {
console.log(error);
});
}
let createUl = document.createElement("ul");
createUl.className += "ul-size";
function myImages(image) {
let content = document.getElementById("add-photos");
let createImg = document.createElement("img");
createImg.className += "image-size";
let createList = document.createElement("li");
createList.className += "img-list";
createImg.src = image;
createList.appendChild(createImg);
createUl.appendChild(createList);
content.appendChild(createUl);
}

getBtn.addEventListener("click", getData);
Copy link

@Abdoulrazack95 Abdoulrazack95 Jul 2, 2020

Choose a reason for hiding this comment

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

Good job Altom, the only thing which is missing error handling when the data is fetched. Try to reorder you these function it looks messy.

14 changes: 14 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,14 @@
<!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="random-image">Press to get image</button>
<div id="add-photos"></div>
<script src="exercise.js"></script>
</body>
</html>
14 changes: 14 additions & 0 deletions week-8/Homework/mandatory/3-dog-photo-gallery/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.image-size {
width: 400px;
display: flex;
}
#container {
display: flex;
}
.ul-size {
display: flex;
flex-wrap: wrap;
}
.img-list {
max-width: 400px;
}
23 changes: 23 additions & 0 deletions week-8/Homework/mandatory/4-programmer-humour/exercise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
console.log("Hi");
function getData(url) {
fetch(url)
.then((response) => {
console.log(response);
return response.json();
})
.then((data) => {
let getData = data.img;
displayImg(getData);
console.log(getData);
})
.catch((error) => {
console.log(error);
});
}
getData("https://xkcd.now.sh/?comic=latest");
let content = document.getElementById("container");
function displayImg(image) {
let createImg = document.createElement("img");
createImg.src = image;
content.appendChild(createImg);
}

Choose a reason for hiding this comment

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

Good Work, The missing part is the error handling code on the fetched data

13 changes: 13 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,13 @@
<!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="container"></div>
<script src="exercise.js"></script>
</body>
</html>
9 changes: 9 additions & 0 deletions week-8/Homework/mandatory/4-programmer-humour/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
body {
background-color: cyan;
}
#container {
display: block;
margin-left: 40%;
margin-right: 30%;
width: 60%;
}