I am trying to make a code that will pick a random image from a list and ask the user to try and identify it. So far I can generate the image but have run into trouble trying to compare the string with the array element.
var imageArray=new Array()
myImages[1]="image1.jpg"
myImages[2]="image2.jpg"
myImages[3]="image3.jpg"
var randNum=Math.floor(Math.random()*imageArray.length);
function pickImg()
{
if {randNum==0)
{
randNum=1;
}
document.write('<img src="'+imageArray[randNum]+'" border=0>');
}
pickImg()
function checkAns()
{
var str = imageArray[randNum];
var n = str.search('textBox');
if(n = -1)
{
alert{"Wrong Answer")
}
Else
{
alert("Right Answer")
}
}
I am at a loss when it comes to the second function and comparing the two strings. Thank you for any help.
if(n == -1)
– janith Dec 5 '12 at 6:24else
, notElse
– Alexander Pavlov Dec 5 '12 at 6:25