I am a java script beginner and I am trying to design a web page that shows two random numbers when refresh. According to these numbers a specific text should appear.
The numbers are images between 0 - 5.
as far, I wrote this code and it worked to change the images when refresh
var images1= new Array ("images/0.png","images/1.png","images/2.png","images/3.png",
"images/4.png","images/5.png");
var images2= new Array ("images/1.png","images/5.png","images/0.png","images/3.png",
"images/4.png","images/2.png");
function RandomImg() {
var x = Math.floor(Math.random() * images1.length);
var img1= document.getElementById('image1');
img1.src = images1[x];
var img2= document.getElementById('image2');
img2.src = images2[x];
}
RandomImg();
after that, according to the images appear, if the first number in the image is bigger than the second, a text should appear and and vice versa.
So my questions are "Is it possible to link each image to a number then execute if statement? or am i going in the wrong direction regarding this ? and how is possible to do that ?"
I did a lot of research but didn't reach anything clear since a week :(
Thanks :)
Aucun commentaire:
Enregistrer un commentaire