update images to match with api response
@ -12,22 +12,36 @@ document.getElementById('terrainForm').addEventListener('submit', function(event
|
||||
})
|
||||
}).then(response => {
|
||||
if (!response.ok) { throw response }
|
||||
return response.json() //we only get here if there is no error
|
||||
return response.json() // we only get here if there is no error
|
||||
}).then(json => {
|
||||
//Handle null encounter
|
||||
let encounterText = json.encounter ? json.encounter : "No Encounter";
|
||||
let resultSection = document.getElementById('resultSection');
|
||||
resultSection.style.textAlign = 'center'; // To center text
|
||||
resultSection.style.fontSize = '1.5em'; // Relative to current font-size (1.5 times the size of the current font)
|
||||
resultSection.style.fontWeight = 'bold'; //To make it bold like H3
|
||||
resultSection.innerText = encounterText;
|
||||
resultSection.innerHTML = '';
|
||||
|
||||
// Create an image element and set its src to the corresponding jpeg image
|
||||
let imgElement = document.createElement("img");
|
||||
imgElement.alt = encounterText;
|
||||
imgElement.width = 500; // You can set width as per your choice
|
||||
imgElement.height = 500; // You can set height as per your choice
|
||||
imgElement.onerror = function() {
|
||||
this.onerror=null;
|
||||
this.src='./img/404.jpg';
|
||||
}
|
||||
imgElement.src = "./img/" + encounterText + ".jpg";
|
||||
|
||||
// Append the image element to the resultSection
|
||||
resultSection.appendChild(imgElement);
|
||||
}).catch(err => {
|
||||
err.text().then(errorMessage => {
|
||||
let imgElement = document.createElement("img");
|
||||
imgElement.src = "./img/404.jpg";
|
||||
imgElement.width = 500;
|
||||
imgElement.height = 500;
|
||||
|
||||
let resultSection = document.getElementById('resultSection');
|
||||
resultSection.style.textAlign = 'center';
|
||||
resultSection.style.fontSize = '1.5em';
|
||||
resultSection.style.fontWeight = 'bold';
|
||||
resultSection.innerText = errorMessage;
|
||||
resultSection.innerHTML = '';
|
||||
resultSection.appendChild(imgElement);
|
||||
})
|
||||
});
|
||||
});
|
BIN
web/img/404.jpg
Normal file
After Width: | Height: | Size: 110 KiB |
BIN
web/img/No Encounter.jpg
Normal file
After Width: | Height: | Size: 88 KiB |
BIN
web/img/android.jpg
Normal file
After Width: | Height: | Size: 132 KiB |
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
BIN
web/img/calthen.jpg
Normal file
After Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
BIN
web/img/crep plant.jpg
Normal file
After Width: | Height: | Size: 99 KiB |
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 100 KiB |
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 92 KiB |
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 77 KiB |
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 95 KiB |
BIN
web/img/pineto.jpg
Normal file
After Width: | Height: | Size: 95 KiB |
BIN
web/img/rakox.jpg
Normal file
After Width: | Height: | Size: 90 KiB |
Before Width: | Height: | Size: 86 KiB After Width: | Height: | Size: 86 KiB |
BIN
web/img/squeekr.jpg
Normal file
After Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 106 KiB |