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

week 8 home work done #1009

Open
wants to merge 2 commits into
base: manchester3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
3 changes: 3 additions & 0 deletions week-8/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
8 changes: 6 additions & 2 deletions week-8/Homework/mandatory/1-practice/1-practice.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ 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} = octocat
{repo} = Hello-World

Choose a reason for hiding this comment

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

Looks good

{pull_number} = 1
-->

2. Describe in a sentence what this API endpoint returns when all of the fields are completed?

<!-- Write your answer here -->
<!-- Provides details for a review comment. I havn't catch that much -->

Choose a reason for hiding this comment

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

Yeah exactly - looks to me like a pull request

15 changes: 8 additions & 7 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,11 @@ 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) {

Choose a reason for hiding this comment

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

Good variable name. All seems to be working fine to me

let greetingText = document.getElementById("greeting-text");
greetingText.innerText = greeting;
});
33 changes: 33 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,33 @@
<!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>
#my_pictures_list {
list-style: none;
}
.button {
height: 50px;
width: 85px;
margin: 0;
}
</style>
</head>
<body>
<div class="main" id="main_container">
<ul>
<li id="my_pictures_list" class="my_list">
<img
src="https://images.dog.ceo/breeds/bullterrier-staffordshire/n02093256_4678.jpg"
alt="random dog pictures"
id="dogImages"
/>
</li>
</ul>
<button id="button" class="button">Next Picture</button>
</div>
<script src="script.js"></script>
</body>
</html>
14 changes: 14 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,14 @@
document.getElementById("button").addEventListener("click", () => {
let makeImage = document.getElementById("dogImages");

fetch(`https://dog.ceo/api/breeds/image/random`)
.then(function (data) {
return data.json();
})
.then(function (newLink) {

Choose a reason for hiding this comment

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

Great variable name newLink - always good to see 😄

makeImage.src = newLink.message;

Choose a reason for hiding this comment

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

Ensure that any image you append onto the document also has an alt attribute too

})
.catch((error) => {
console.log(error);

Choose a reason for hiding this comment

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

Maybe here you could also think about displaying an error message in case something goes wrong

});
});
12 changes: 12 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,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<img src="" alt="" id="image" />
<script src="script.js"></script>
</body>
</html>
16 changes: 16 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,16 @@
fetch("https://xkcd.now.sh/?comic=latest")
.then(function (data) {
if (data.ok) {

Choose a reason for hiding this comment

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

Interesting that it has this ok property - I've never seen that before

console.log("success");
} else {
console.log("unsuccessful");
}
return data.json();
})
.then(function (newData) {
const newImage = document.getElementById("image");
newImage.src = newData.img;

Choose a reason for hiding this comment

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

Again don't forget the alt attribute here, Iman

})
.catch((error) => {
console.log(error);
});