arrays - javascript solitare game, Getting javascript to check childNode values, is there an implied else? -


i'm attempting first solitare game using javascript code. found brainjar.com resource project, , far good. i've learned loads javascript way , i've managed primitive form of game, albeit based on forms. not neat-o, functional.

only now, i've gotten stuck.

every time attempt "if else" check on press of button, thing barfs. in game chooses reset itself, or refuses work @ all. figure must overlooking somewhere.

the code huge mess post here, (me being beginner , all, know it's sloppy) link here should take @ source (warning, may need zoom out bit on display side, haven't optimized thing yet) :

http://pluckzilla.com/game/clockgame.html

the function ugly green button near top calls one:


//game play  //begin 12  function twelve(){  hand12.combine(fingering); fingering.addcard(hand12.deal()); display();   //and need figure out way make sure rank of queen allowed in stack.   } 

help?


adding details requested

//example on how card objects stack, , there lot of them. card   objects in separate js file  left = 0; top  = 0; el = document.getelementbyid("fingering"); while (el.firstchild != null) el.removechild(el.firstchild); (i = 0; < fingering.cardcount(); i++) { node = fingering.cards[i].createnode(); node.firstchild.style.visibility = "visible"; node.style.left = left + "em"; node.style.top  = top  + "em"; el.appendchild(node); left += .20; top  += 0.05; }  

odd thing is, it's if there implied "else" going on when if set this:

function twelve(){ if (fingering.cards[0].rank==="10") hand12.combine(fingering); fingering.addcard(hand12.deal());   display(); 

the first card tried 10, , card exchange worked beautifully between both stacks, subsequent cards did not exchange fully, , enough hand 12 empty, , fingering, supposed have 1 card max, had 5.

what's going on?

i see brainjar declared newarray blackjack game score player's hand, score not needed in game. (the game end if there 4 kings in middle stack, haven't coded event yet.)

is there such thing implied else in javascript?


shout out messiah there, got brain working somewhat, , allowed part of problem solved. have figure out how card exchange stop when card not correct card.


added code.. works intended...

function twelve(){ if (fingering.cards[0].rank!=="10") alert ("nonono");  if (fingering.cards[0].rank==="10") hand12.combine(fingering);  fingering.addcard(hand12.deal()); display(); 

however, annoying implied "else" effect still happening on ==="10" version, making new code moot: running last 2 lines regardless of card checked. ideas?

aha!

make 2 steps 1 declaring separate function, , run anyway.

 //begin 12   function twelve(){  var card;  if (fingering.cards[0].rank!=="10")  alert ("nonono");   if (fingering.cards[0].rank==="10")  cardexchange();  display();    //and need figure out way make sure rank of queen allowed in stack.    }  function cardexchange(){  hand12.combine(fingering);   fingering.addcard(hand12.deal());  } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -