javascript - Switch case not working for Images stored in array -
relating previous question , had images which(if 3 of specific image) same, wanted message appear, followed several guidelines previous question still cant work.
previous question: how make if statement specific image source?
it prints else statement, if 3 images of x appear, prints nothing main message, same problem occurs when 3 images of y appear(at once) or z. appreciated.
new code (tad bit) :
function xyz() { if((document.test.test1.src == document.test.test2.src && document.test.test2.src == document.test.test3.src )) switch (document.test.test1.src == document.test.test2.src == document.test.test3.src) { case "x": document.test.banner.value =("3 x")// stuff break; case "y": document.test.banner.value =("5 y") break; case "z": document.test.banner.value =("8 z") break; } else { document.test.usertokens.value=document.test.usertokens.value-document.test.bet.value; document.test.banner.value="no match - lost "; } }
here problem:
switch (document.test.test1.src == document.test.test2.src == document.test.test3.src)
the switch statement evaluates value put parenthesis. comparing .src
s, return boolean switch evaluate instead of strings hoping for. no need compare them in switch, seeing know same. need know 1 of them.
secondly, found interesting used syntax (a == b == c
. did testing , does. equivalent ((a==b)==c)
. evaluates left right. first, (a==b)
return boolean. compares boolean c, , i'm guessing "c" isn't boolean, return false
.
looking @ previous question
switch (document.test.test1.src) { case 'y': ........ break; case 'x' ........ break; }
,as suggested dewd, seems appropriate choice if decide stick switch.
hope helped.
Comments
Post a Comment