From fe235cf4733ae62c3688f9f97cde4177648dce2a Mon Sep 17 00:00:00 2001 From: tin33392js Date: Sun, 27 Nov 2022 23:55:51 +0700 Subject: [PATCH] Fix_URL use Picsum as an alternative for Unsplash random --- random-image-generator/script.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/random-image-generator/script.js b/random-image-generator/script.js index 0f9b658..74b2011 100644 --- a/random-image-generator/script.js +++ b/random-image-generator/script.js @@ -1,17 +1,22 @@ -const container = document.querySelector('.container') -const unsplashURL = 'https://source.unsplash.com/random/' -const rows = 5 +const container = document.querySelector('.container'); +const unsplashURL = 'https://source.unsplash.com/random/'; +const picsumURL = 'https://picsum.photos'; +const rows = 5; -for(let i = 0; i < rows * 3; i++) { - const img = document.createElement('img') - img.src = `${unsplashURL}${getRandomSize()}` - container.appendChild(img) +for (let i = 0; i < rows * 3; i++) { + const img = document.createElement('img'); + /* Unplash's server is down at the moment. Use 'picsum' instead + img.src = `${unsplashURL}${getRandomSize()}`; + */ + // Picsum URL: https://picsum.photos///? + img.src = `${picsumURL}/${getRandomNr()}/${getRandomNr()}/?${i}`; + container.appendChild(img); } function getRandomSize() { - return `${getRandomNr()}x${getRandomNr()}` + return `${getRandomNr()}x${getRandomNr()}`; } function getRandomNr() { - return Math.floor(Math.random() * 10) + 300 -} \ No newline at end of file + return Math.floor(Math.random() * 10) + 300; +}