-
-
Notifications
You must be signed in to change notification settings - Fork 458
Shahd week 8 #1003
Shahd week 8 #1003
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> |
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(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
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> |
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(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, works well!