This repository has been archived by the owner on Oct 26, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 458
Leidas week 8 homework #1005
Open
Leidagandy
wants to merge
1
commit into
CodeYourFuture:manchester3
Choose a base branch
from
Leidagandy:leida-week-8
base: manchester3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Leidas week 8 homework #1005
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!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="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" | ||
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" | ||
crossorigin="anonymous" | ||
/> | ||
<style> | ||
#fact { | ||
display: none; | ||
} | ||
</style> | ||
<title>Number Facts</title> | ||
</head> | ||
<body class="bg-dark"> | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-md-6 mx-auto"> | ||
<div class="card bg-primary text-white mt-5 p-4"> | ||
<h1>Number Facts</h1> | ||
<p>Enter a number and get a random fact</p> | ||
<input | ||
type="number" | ||
class="form-control form-control-lg" | ||
id="numberInput" | ||
placeholder="Enter any number..." | ||
/> | ||
<div id="fact" class="card-body"> | ||
<h4 class="card-title"> | ||
Number Fact | ||
</h4> | ||
<p id="factText" class="cardText"></p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<script> | ||
let fact = document.querySelector("#fact"); | ||
let factText = document.querySelector("#factText"); | ||
let numberInput = document.querySelector("#numberInput"); | ||
numberInput.addEventListener("input", getFactFetch); | ||
|
||
// function getFactAjax() { | ||
// let number = numberInput.value; | ||
// let xhr = new XMLHttpRequest(); | ||
// xhr.open("GET", "http://numberapi.com/" + number); | ||
// xhr.onload = function () { | ||
// if (this.status == 200 && number != "") fact.style.display = "block"; | ||
// factText.innerText = this.responseText; | ||
// }; | ||
// xhr.send(); | ||
// } | ||
function getFactFetch() { | ||
let number = numberInput.value; | ||
fetch("http://numberapi.com/" + number) | ||
.then((response) => response.text()) | ||
.then((data) => { | ||
if (number != "") { | ||
fact.style.display = "block"; | ||
fact.innerText = data; | ||
} | ||
}) | ||
.catch((error) => console.log(error)); | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
|
||
<style> | ||
body { | ||
background-color: aquamarine; | ||
} | ||
ul { | ||
list-style: none; | ||
} | ||
#getImage { | ||
width: 150px; | ||
height: 40px; | ||
margin-bottom: 50px; | ||
} | ||
</style> | ||
<title>Dog Images Gallery</title> | ||
</head> | ||
<body> | ||
<h3> | ||
Hit the gray generate button and you will get a new dog image. | ||
</h3> | ||
<button id="getImage">generate</button> | ||
<div id="container"> | ||
<ul id="dogList"></ul> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const dogList = document.getElementById("dogList"); | ||
const api_url = "https://dog.ceo/api/breeds/image/random"; | ||
|
||
const button = document.getElementById("getImage"); | ||
button.addEventListener("click", getRandomDog); | ||
|
||
function getRandomDog() { | ||
fetch(api_url) | ||
.then((response) => response.json()) | ||
.then((dog) => { | ||
console.log(dog); | ||
const li = document.createElement("li"); | ||
const img = document.createElement("img"); | ||
img.classList.add("dogImages"); | ||
img.src = dog.message; | ||
li.appendChild(img); | ||
dogList.appendChild(li); | ||
}) | ||
.catch((error) => { | ||
console.log("error!!!"); | ||
console.error(error); | ||
}); | ||
} | ||
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. Good Job Leida, you forgot to implement error handling code at the fetched data. Implement that. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!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>Programmer Jokes</title> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<h2 id="jokeTitle"></h2> | ||
<img id="joke" src="" alt="" /> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const api_url = "https://xkcd.now.sh/?comic=latest"; | ||
|
||
let jokeImage = document.getElementById("joke"); | ||
let jokeTitle = document.getElementById("jokeTitle"); | ||
|
||
function getJoke() { | ||
fetch(api_url) | ||
.then((response) => response.json()) | ||
.then((joke) => { | ||
console.log(joke); | ||
jokeTitle.innerText = joke.title; | ||
jokeImage.src = joke.img; | ||
jokeImage.alt = joke.alt; | ||
}) | ||
.catch((error) => { | ||
console.log("error!!!"); | ||
console.error(error); | ||
}); | ||
} | ||
getJoke(); | ||
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 function is correct, calling the function at line 20 is not appropriate. what you could do separate the fetching and the getJoke then call getJoke in the .then() or the easiest way apply the innerText in the .then() . Work on that. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#container { | ||
text-align: center; | ||
} | ||
img { | ||
display: block; | ||
margin: 0 auto; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Well done Leida.