Skip to content

Commit

Permalink
Implemented display random image. Multiple images can be displayed, w…
Browse files Browse the repository at this point in the history
…ith the newest one displayed first
  • Loading branch information
JoeProgrammer88 committed Jun 6, 2024
1 parent 70538ae commit f638623
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ async function getRandomDogImage() {
return data;
}
function displayDogImage(dogData) {
let displayDiv = document.getElementById("display");
let img = document.createElement("img");
img.src = dogData.message;
img.style.width = "300px";
displayDiv.insertBefore(img, displayDiv.firstChild);
}
function displayError(error) {
}
11 changes: 11 additions & 0 deletions ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ async function getRandomDogImage(){

function displayDogImage(dogData:RandomImageResponse){
// Todo: Display image on page
let displayDiv = document.getElementById("display");

// Create an image element in memory
let img = document.createElement("img");
img.src = dogData.message;

// Use css to resize the image
img.style.width = "300px";

// Add image as the first child of the display div but keep the previous images
displayDiv.insertBefore(img, displayDiv.firstChild); // insert the new image before the current first image
}

function displayError(error:Error){
Expand Down

0 comments on commit f638623

Please sign in to comment.