lundi 27 juillet 2020

How can I display an image from a URL with a random number in it?

I am trying to make a chemical compound generator of some sort, using PubChem. I have successfully generated a link to the website with a random number (e.g. https://pubchem.ncbi.nlm.nih.gov/compound/123456), as well as a link to the image (e.g. https://pubchem.ncbi.nlm.nih.gov/image/imgsrv.fcgi?cid=123456&t=l). However, when I try to embed the random image link into the document, it doesn't show up. I am only a starter when it comes to programming.

var lower = 0;
var upper = 100000000;
var rand = (Math.floor(Math.random() * (upper - lower)) + lower)
var url = "https://pubchem.ncbi.nlm.nih.gov/compound/" + rand
var img = "https://pubchem.ncbi.nlm.nih.gov/image/imgsrv.fcgi?cid=" + rand + "&t=l"
document.write("<a href=" + url + ">" + url + "</a>");
document.write("</br><a href=" + img + ">" + rand + "</a>");
document.write("</br><img src=" + img + "alt=" + rand + ">")



Aucun commentaire:

Enregistrer un commentaire