I've got this 'if else' loop and the only way i can get the 'count number of turns' to work is by having the variables inside the 'if' statement which doesn't seem right to me.
My main concern though is right at the very bottom of the code, i've tried to take the SCORE variable and see if it is greater than HIGH SCORE, if so HIGH SCORE becomes OLD SCORE and SCORE becomes HIGH SCORE.
For some reason it keeps coming up with error, object expected. I've checked for spelling mistakes and the usual stuff but cant work out whats going on.
Any help muchely appreciated.
Expand|Select|Wrap|Line Numbers
- function turnOver(e)
- {
- if (matchCount<8 & !matched[e.name])
- {
- if (clicked<1)
- {
- firstCard=e; //grab first card object
- pair=cards[firstCard.name]; //get first pair number from cards array
- e.src=document.images["load"+pair].src; //flip over first card
- clicked++;
- }
- else
- {
- e.src=document.images["load"+cards[e.name]].src; //flip over second card
- if (pair!==cards[e.name])
- { //check for snap
- alert("That's not a match, try again!");
- firstCard.src=document.images["load0"].src; //flip first card back
- e.src=document.images["load0"].src; //flip second card back
- count1 ++;
- }
- else
- {
- //This is a match so record matched cards and increase matchCount
- matched[firstCard.name]=true;
- matched[e.name]=true;
- matchCount++;
- }
- clicked=0;
- }
- }
- var plus = (matchCount*5);
- var minus = count1;
- var score = (plus - minus);
- if (matchCount > 7)
- {
- alert("Congratulations you matched "+matchCount+" pairs, for "+plus+" points with "+minus+" misses, giving you " +score+ " overall");
- }
- }
- var high score=0;
- var old score=0;
- if (score > high score)
- {
- old score = high score;
- high score = score;
- alert("gfag "+high score+" gfgfg");
- }