-
-
Couldn't load subscription status.
- Fork 83
NW6| BakhatBegum | Module-JS3 | Feature/humor |Sprint-3 #300
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,3 @@ | ||
| { | ||
| "liveServer.settings.port": 5501 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <!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"> | ||
| <script defer src="script.js"></script> | ||
| <title>Programmer-humour</title> | ||
| </head> | ||
| <body> | ||
|
|
||
|
|
||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
|
|
||
| function getImageFetch(){ | ||
| return fetch('https://xkcd.now.sh/?comic=latest').then((response) => { | ||
| if(!response.ok){ | ||
| return "Error"; | ||
| }else{ | ||
| return response.json(); | ||
| } | ||
| }); | ||
| } | ||
| getImageFetch(); | ||
|
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. Because we call |
||
|
|
||
| let imageDiv = document.createElement('div'); | ||
| document.body.appendChild(imageDiv); | ||
|
|
||
| function displayData(){ | ||
|
|
||
| getImageFetch().then((data) => { | ||
| if(!data){ | ||
| console.log("data can not found"); | ||
| } | ||
| const image = data.img; | ||
|
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. Could this variable name be a bit more descriptive? For example, |
||
|
|
||
| const createImage = document.createElement('img'); | ||
|
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. I really like how you create the image element inside JavaScript! It means the user doesn't see a 'broken image' when they first load the page, creating a nice user experience |
||
| createImage.src = image; | ||
| imageDiv.appendChild(createImage); | ||
| } ) | ||
| } | ||
| displayData(); | ||
|
|
||
| window.onload = displayData; | ||
|
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. When I launch the page, I see the same image appear twice. Having a look at these final lines of the JavaScript file, can you think why that might be? |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| body{ | ||
|
|
||
| background-color: antiquewhite; | ||
| display: grid; | ||
| grid-template-columns: auto; | ||
| align-items: center; | ||
| justify-content: center; | ||
| margin-top: 90px; | ||
| } |
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.
Instead of just returning the text "Error", we could instead throw an exception. This is a large topic to cover here, so reach out on Slack if you have any questions on what this means!