Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a lot of things going on. And some superfluous code.<br> I think the main problem stems from having a cookie called "gamesWonCount" and another cookie called "getCount". You also have 2 variables and a function that keep track of this number (winnerCount, gamesWin, winnerCount()). </p> <p>The first thing is to keep track of that number in one place. Let's call it "winnerCount". </p> <p>Now let's create a function called "calculateWinnerCount", this will calculate the number of wins based on your card results. Note that the base amount of "winnerCount" is set to your cookies value.</p> <p>Since we're always manipulating the variable called winnerCount we can use that in the alert function. </p> <p>Here is the code:</p> <pre><code>function getCookieOne(c_name) { var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i&lt;ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x==c_name) { return unescape(y); } } } function setCookieOne(c_name,value,exdays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; } var winnerCount = getCookieOne('gamesWonCount') || 0; function calculateWinnerCount() { if (cardOnePoints + cardTwoPoints === 21) { winnerCount = winnerCount + 1; } } function checkCookie() { var username=getCookieOne("username"); if (username!=null &amp;&amp; username!="") { alert("Sup " + username+ "!!! Woah man, you've won " + winnerCount + " game(s)!!!" ); } else { username=prompt("Please enter your name:",""); if (username!=null &amp;&amp; username!="") { setCookieOne("username",username,365); } } } </code></pre> <p>I'm not sure how you are using or calling these functions. But if you call calculateWinnerCount() at the end of every card game, it should add a number to your winnerCount variable which holds the number of total wins that you have stored in your cookie and that you have won today.</p> <p>You may also want to set the cookie value everytime you calculateWinnerCount() like this:</p> <pre><code>function calculateWinnerCount() { if (cardOnePoints + cardTwoPoints === 21) { winnerCount = winnerCount + 1; setCookieOne("gamesWonCount", winnerCount, 14); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload