-
-
Notifications
You must be signed in to change notification settings - Fork 455
Nawal week 8 #1000
base: manchester3
Are you sure you want to change the base?
Nawal week 8 #1000
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,3 @@ | ||
{ | ||
"liveServer.settings.port": 5501 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,23 @@ 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(); | ||
fetch('https://codeyourfuture.herokuapp.com/api/greetings') | ||
.then((response )=> { | ||
return response.text(); | ||
}) | ||
.then(function(greeting) { | ||
// Write the code to display the greeting text here | ||
}); | ||
|
||
.then((greeting)=> { | ||
|
||
addGreeting(greeting) | ||
}) | ||
|
||
// .catch((error) => { | ||
// console.log(error); | ||
|
||
// }) | ||
|
||
const addGreeting = (greetingObj) => { | ||
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. I would call the parameter |
||
const pElement = document.getElementById("greeting-text"); | ||
pElement.textContent = `${greetingObj}`; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<title>Document</title> | ||
<style> | ||
.list{ | ||
display: flex; | ||
justify-content: center; | ||
text-align: center; | ||
margin: 0 50px; | ||
padding: 30px; | ||
} | ||
img{ | ||
height: 500px; | ||
width: auto; | ||
} | ||
|
||
button{ | ||
display: flex; | ||
justify-content: center; | ||
background-color: brown; | ||
color: cornsilk; | ||
font-size: 16px; | ||
} | ||
|
||
</style> | ||
</head> | ||
<body> | ||
<div id="main"> | ||
|
||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
function getImage(){ | ||
fetch ('https://dog.ceo/api/breeds/image/random') | ||
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. Cool, this works well! How would you implement error handling? Remember you can do any DOM manipulation you like, so you can show any messaging to the user... |
||
.then((response )=> { | ||
return response.json(); | ||
}) | ||
|
||
.then((randomDogImg)=> { | ||
//console.log(randomDogImg.message); | ||
|
||
getRandomDogImg(randomDogImg) | ||
}) | ||
|
||
.catch((error) => { | ||
console.log(error); | ||
|
||
}) | ||
} | ||
|
||
|
||
const main = document.getElementById('main') | ||
const btnElement = document.createElement('button') | ||
btnElement.innerText = 'Show next image' | ||
const ulElement = document.createElement('ul') | ||
main.append(btnElement, ulElement) | ||
const liElement =document.createElement('li') | ||
liElement.classList='list' | ||
const imgElement =document.createElement('img') | ||
const containerList = ulElement.appendChild(liElement) | ||
const imgList = liElement.appendChild(imgElement) | ||
|
||
const getRandomDogImg= (dogImg) => { | ||
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. This might be more appropriately called |
||
imgElement.src = dogImg.message | ||
|
||
} | ||
|
||
// Next button | ||
btnElement.addEventListener('click', getImage) | ||
|
||
|
||
|
||
|
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"> | ||
<link rel="stylesheet" href="style.css"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<div id="main"> | ||
|
||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function getHumour(){ | ||
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. As before - works well! Think about error handling. |
||
fetch ('https://xkcd.now.sh/?comic=latest') | ||
.then((response )=> { | ||
return response.json(); | ||
}) | ||
|
||
.then((data)=> { | ||
console.log(data.title); | ||
console.log(data.alt); | ||
|
||
getData(data) | ||
}) | ||
|
||
.catch((error) => { | ||
console.log(error); | ||
|
||
}) | ||
} | ||
|
||
const main = document.getElementById('main') | ||
const imgEl =document.createElement('img') | ||
main.append(imgEl) | ||
|
||
const getData= (data) => { | ||
|
||
imgEl.src = data.img | ||
|
||
} | ||
|
||
getHumour() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
*{ | ||
box-sizing: border-box; | ||
background-color: rgb(132, 91, 138); | ||
} | ||
|
||
img{ | ||
display: flex; | ||
padding: 70px 500px; | ||
height: 600px; | ||
border-inline: rgb(218, 64, 97); | ||
|
||
} |
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.
Yes, and specifically pull request comments.