Hmm, it's a bit rich me offering advice when I had never seen a Arduino a month ago.. but I have been programming since 1974 when I learned Fortran.
Here are two bits of advice....
The first bit is, put comments in the sketch. Put lots of comments in. They don't take up any room since the compiler zaps them anyway so they aren't lurking in the Arduino. Comments help you remember wth you were trying to do at 3am when you read the code the next day. But, maybe more important as far as the Forum goes, they help our fellow Arduiners try to figure out what we meant when they try to help us with our code.
On the subject of comments, remember they are a debugging tool too. If you suspect the problem is in a certain area of code, bypass that code with a /*..... */ or a bunch of //s to see if the problem goes away. In the old days of BASIC, a comment line started with the word REM for REMark, so this technique is still known to Old Timers as "remming it out".
Second, use the serial monitor to help debug faulty code... I put loads of lines like
Serial.print("Inside the middle nested if") so that if somethng inside my "if" isn't working I can at least see if I got there in the first place. If you're not sure a value is incrementing correctly, print it out:
Serial.print(myVal) to see if your arithmetic is correct. (Remember to take these lines out later, or comment them out so they can be re-instated easily if you get more problems)