-
-
Notifications
You must be signed in to change notification settings - Fork 274
London | 26-ITP-May | Damilola Odumosu | Sprint 3 | Programmer humour #551
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
base: main
Are you sure you want to change the base?
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,16 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>XKCD Comic</title> | ||
| <link rel="stylesheet" href="style.css"> | ||
| </head> | ||
| <body> | ||
| <div id="comic"> | ||
| <h2 id="title"></h2> | ||
| <img id="image" alt=""> | ||
| <p id="alt"></p> | ||
| </div> | ||
| <script src="script.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| const title = document.getElementById("title"); | ||
| const image = document.getElementById("image"); | ||
| const alt = document.getElementById("alt"); | ||
|
|
||
| async function getImg() { | ||
| const url = "https://xkcd.now.sh/?comic=latest"; | ||
| try { | ||
| const response = await fetch(url); | ||
| if (!response.ok) { | ||
| throw new Error(`Response status: ${response.status}`); | ||
|
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. Nice use of exception here! |
||
| } | ||
| const result = await response.json(); | ||
| title.textContent = result.safe_title; | ||
| image.src = result.img; | ||
| alt.textContent = result.alt; | ||
| console.log(result); | ||
| } catch (error) { | ||
| console.log(error.message); | ||
|
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. Is there a better function to log errors?
Author
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. oh yes, console.error |
||
| } | ||
| } | ||
| getImg(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #comic { | ||
| text-align: center; | ||
| max-width: 800px; | ||
| margin: 0 auto; | ||
| } | ||
|
|
||
| #image { | ||
| max-width: 100%; | ||
| } |
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.
Do you think this function name clearly describes what it does?
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.
maybe getImage could be better?
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.
I was mostly thinking here that it in addition to getting image it sets values for some text fields, but this is just a nitpick.