-
-
Notifications
You must be signed in to change notification settings - Fork 275
London | 26-ITP-May | Edina Kurdi | Sprint 3 | Programmer Humour #555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
edinakurdi
wants to merge
9
commits into
CodeYourFuture:main
Choose a base branch
from
edinakurdi:feature/xkcd
base: main
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.
+68
−0
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0ae9670
initial html
edinakurdi dc9eeb0
create JS file
edinakurdi 7dd5728
create CSS file
edinakurdi 731c8ba
add img tag in html
edinakurdi 04966d8
write API call to https://xkcd.now.sh/?comic=latest
edinakurdi 626309f
implement loadComic() async function
edinakurdi ec7afc2
log the data to the console
edinakurdi b7e7c6f
add basic css formatting
edinakurdi f588c54
change function parameter to avoid shadowing
edinakurdi 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 hidden or 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,18 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
|
|
||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Programmer humour</title> | ||
| <link rel="stylesheet" href="style.css"> | ||
| <script src="script.js" defer></script> | ||
| </head> | ||
|
|
||
| <body> | ||
| <h1>Programmer humour</h1> | ||
| <img src="" alt=""> | ||
|
|
||
| </body> | ||
|
|
||
| </html> |
This file contains hidden or 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,35 @@ | ||
| const endpointAPI = "https://xkcd.now.sh/?comic=latest"; | ||
| async function fetchData(url) { | ||
| try { | ||
| const response = await fetch(url); | ||
| if (!response.ok) { | ||
| throw new Error(`Error! Status: ${response.status}`); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
|
|
||
| console.log(data); | ||
| return data; | ||
| } catch (error) { | ||
| console.error("Could not fetch data", error); | ||
| } | ||
| } | ||
|
|
||
| async function loadComic() { | ||
| try { | ||
| const data = await fetchData(endpointAPI); | ||
| if (!data) { | ||
| throw new Error("No data received from the API."); | ||
| } | ||
| const imgEl = document.querySelector("img"); | ||
| imgEl.src = data.img; | ||
| imgEl.title = data.title; | ||
| imgEl.alt = data.alt; | ||
| } catch (error) { | ||
| console.error("Error loading comic:", error); | ||
| document.querySelector("h1").textContent = | ||
| "Image failed loading. Please try again later"; | ||
| } | ||
| } | ||
|
|
||
| loadComic(); | ||
This file contains hidden or 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,15 @@ | ||
| body { | ||
| background-color: #e0f5f5; | ||
| font-family: sans-serif; | ||
| text-align: center; | ||
| padding: 2rem; | ||
| } | ||
|
|
||
| h1 { | ||
| color: #1a6b6b; | ||
| font-size: 3rem; | ||
| } | ||
|
|
||
| /* img { | ||
| margin: 0 auto; | ||
| } */ |
Oops, something went wrong.
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.
endpointAPI is used both outside and inside the function. This can be confusing, so Its best to rename the function parameter to make the code clearer and avoid shadowing.
more on shadowing here:
https://www.geeksforgeeks.org/javascript/variable-shadowing-in-javascript/
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.
this is now corrected. thank you