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

Nawal week 8 #1000

Open
wants to merge 5 commits 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 week-8/Homework/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
5 changes: 4 additions & 1 deletion week-8/Homework/mandatory/1-practice/1-practice.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ The following endpoint is publicly available from Github
1. What would you put in the following fields? `{owner}`, `{repo}`, `{pull_number}`?

<!-- Write your answer here -->

`{owner}`- username
`{repo}` - name of repo
`{pull_number}`- pull request number
2. Describe in a sentence what this API endpoint returns when all of the fields are completed?

<!-- Write your answer here -->
Lists details of a pull request by providing its number
Copy link
Member

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.

25 changes: 19 additions & 6 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,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) => {
Copy link
Member

Choose a reason for hiding this comment

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

I would call the parameter greeting as it is technically a string, not an object.

const pElement = document.getElementById("greeting-text");
pElement.textContent = `${greetingObj}`;

}
37 changes: 37 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,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>
41 changes: 41 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,41 @@
function getImage(){
fetch ('https://dog.ceo/api/breeds/image/random')
Copy link
Member

Choose a reason for hiding this comment

The 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) => {
Copy link
Member

Choose a reason for hiding this comment

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

This might be more appropriately called displayImage. Try to keep the indentation consistent.

imgElement.src = dogImg.message

}

// Next button
btnElement.addEventListener('click', getImage)




15 changes: 15 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,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>
30 changes: 30 additions & 0 deletions week-8/Homework/mandatory/4-programmer-humour/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function getHumour(){
Copy link
Member

Choose a reason for hiding this comment

The 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()
12 changes: 12 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,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);

}