homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Loop with number
for card game

 3:12 am on May 29, 2009 (gmt 0)

I am creating a simple local card game and stalled with one function.

I am trying to check an array of numbers to see if it's "straight", eg. 789 or 34567.

for (i=0; i<cardArray.length; i++){

var s=Number(cardArray[i+1])-Number(cardArray[i]);

var cardCheck="valid";

var cardCheck="notvalid";



The above code sometimes work sometimes not. Appreciate your help.. Thanks



 3:48 am on May 29, 2009 (gmt 0)

As cardCheck is set each time, the final value depends only on last 2 cards.

Use innocent until proved otherwise method.

var cardCheck="valid";
for (var i=0; i<(cardArray.length-1); i++){
var s=Number(cardArray[i+1])-Number(cardArray[i]);

You will need to also that there are at least 2 cards


 1:18 am on May 30, 2009 (gmt 0)

That's perpect. Thanks a lot.


 11:37 am on Jun 10, 2009 (gmt 0)

I also want to check the card suits if all are the same. I have an array of cards suits and would like to find out if all the values are the same. Thanks a lot for the help.


 12:04 pm on Jun 10, 2009 (gmt 0)

Much the same

var suiteCheck="valid";
for (var i=0; i<(suiteArray.length-1); i++){
if( suiteArray[i+1] !== suiteArray[i] ){suiteCheck="notvalid";}



 12:29 pm on Jun 10, 2009 (gmt 0)

Thanks a lot really. I missed the -1 part. Thanks again.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved