(before anything, should know js skills basic)
i'm trying make own "rapid sorting" game "brainwars" on smartphones.
basically should is:
step 1: randomise 1 of 3 pictures available , show image. step 2: if image same last 1 ( ) step 3: if image not same last 1 ( else )
for , have folder named "images" 3 png's inside it. far have this:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>demo</title> <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.0.min.js"></script> <script> var random_images_array = ['1.png', '2.png', '3.png']; var lastimage = ""; function getrandomimage(imgar, path) { path = path || 'images/'; // default path hier opgeven var num = math.floor(math.random() * imgar.length); var img = imgar[num]; var imgstr = '<img src="' + path + img + '" alt = "">'; document.write(imgstr); document.close(); } $(function() { $('#btn').click(function() { getrandomimage(random_images_array, 'images/'); settimeout(function() { getrandomimage(random_images_array, 'images/'); }, 2000); }); }); </script> </head> <body> <button id="btn">go</button> </body> </html>
how can 1 achieve ?
what creating lastimage variable...
var random_images_array = ['1.png', '2.png', '3.png']; var lastimage="";
then:
var img = imgar[num]; if (img==lastimage) {do something} else {lastimage=img; ... document.write(imgstr);}
Comments
Post a Comment