Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

random image and link js

<script type="text/javascript">
//Javascript Created by Computerhope https://www.computerhope.com/
//store the quotations in arrays
var images = [],
index = 0;
images[0] = "<a href = 'https://www.computerhope.com/'><img src='https://www.computerhope.com/banners/banner.gif' alt='Visit Computer Hope'></a>";
images[1] = "<a href = 'https://www.computerhope.com/history'><img src='https://www.computerhope.com/banners/banner2.gif' alt='Computer History'></a>";
images[2] = "<a href = 'https://www.computerhope.com/'><img src='https://www.computerhope.com/banners/banner3.gif' alt='Visit Computer Hope'></a>";
index = Math.floor(Math.random() * images.length);
document.write(images[index]);
//done
</script>
Comment

random image generator javascript using objects

//Data
let memesData= {
    "success": true,
    "data": {
        "memes": [
            {
                "id": "181913649",
                "name": "Drake Hotline Bling",
                "url": "https://i.imgflip.com/30b1gx.jpg",
                "width": 1200,
                "height": 1200,
                "box_count": 2
            },
            {
                "id": "87743020",
                "name": "Two Buttons",
                "url": "https://i.imgflip.com/1g8my4.jpg",
                "width": 600,
                "height": 908,
                "box_count": 3
            },
            {
                "id": "112126428",
                "name": "Distracted Boyfriend",
                "url": "https://i.imgflip.com/1ur9b0.jpg",
                "width": 1200,
                "height": 800,
                "box_count": 3
            },
            {
                "id": "131087935",
                "name": "Running Away Balloon",
                "url": "https://i.imgflip.com/261o3j.jpg",
                "width": 761,
                "height": 1024,
                "box_count": 5
            },
            {
                "id": "247375501",
                "name": "Buff Doge vs. Cheems",
                "url": "https://i.imgflip.com/43a45p.png",
                "width": 937,
                "height": 720,
                "box_count": 4
            },
            {
                "id": "129242436",
                "name": "Change My Mind",
                "url": "https://i.imgflip.com/24y43o.jpg",
                "width": 482,
                "height": 361,
                "box_count": 2
            },
            {
                "id": "124822590",
                "name": "Left Exit 12 Off Ramp",
                "url": "https://i.imgflip.com/22bdq6.jpg",
                "width": 804,
                "height": 767,
                "box_count": 3
            }
        ]
    }
}
//Extracting images only from the data in an array
let varr=[]
let memeimg = memesData.data.memes.map(x =>{
     varr.push(x.url)
})
// Using some math.random function and we are good to go
let randomImgGenerator=(params)=>{
      return params[Math.floor(Math.random()*params.length)]        
}
console.log(randomImgGenerator(varr))
Comment

PREVIOUS NEXT
Code Example
Javascript :: detect system dark mode javascrip 
Javascript :: convert array to object in javascript 
Javascript :: how to print line break in javascript 
Javascript :: javascript range 
Javascript :: PG::DuplicateTable: ERROR: relation already exists 
Javascript :: how to iterate object inside object in javascript 
Javascript :: loopback model count 
Javascript :: patch swagger 
Javascript :: get express variable 
Javascript :: jquery addeventlistener 
Javascript :: jquery click hold down 
Javascript :: como saber si una fecha es mayor que otra en javascript 
Javascript :: moment day in range 
Javascript :: google oauth logout 
Javascript :: check if string is datestring javascript 
Javascript :: iconify/react - npm 
Javascript :: alternate color to table row jquery 
Javascript :: js select element inside of div 
Javascript :: javascript synchronous wait 
Javascript :: remove first and last character javascript 
Javascript :: audio in react 
Javascript :: react native disable the text input 
Javascript :: factorial function javascript 
Javascript :: ant design not working in react js 
Javascript :: javascript get 24 hour time 
Javascript :: how create an index mongodb 
Javascript :: toggle in react 
Javascript :: javascript check if time is less than 
Javascript :: how to get all form values in javascript 
Javascript :: jquery index of element 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =