Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I took out a BUNCH of your code and tried to clean it up.</p> <p>Also, I want to point out that I butchered the crap of HTML5, as I see you are just learning. There are some BAD practices in this code, but for what you are trying to accomplish I think/hope you can gleam the import bits out with adopting this as dogma (I got lazy!).</p> <p>Some things to be aware of:</p> <ol> <li>JavaScript is CaSeSeNsItIvE. So if you start calling variables "clickcounter" and then try to reference as "clickCounter" you'll run into a bunch of errors.</li> <li>The code I provided below: I mixed CSS in the HTML, and HTML (poor choice of tags) in the JavaScript. I see you had a CSS file, well - yeah, you didn't post it so I didn't have access to it. So I just took it out and added colors throughout. </li> <li>Remember the power of <code>console.log("your messages goes here");</code>. It's a poor mans debugger/manhole into what your code is doing at any one time. Use it while you learn so you can see what the expected values are (FYI: most browsers have "developer tools" -- if you are using Chrome, then hit <code>F12</code> -- this way you can SEE the CONSOLE messages (and the ERRORS in your JavaScript as you run it).</li> <li>Don't be afraid to use functions heavily. It's a great way to organize your code and force yourself to pick up good practices.</li> </ol> <p>Here is the code:</p> <pre><code>&lt;HTML&gt; &lt;HEAD&gt; &lt;script&gt; function clickCounter() { if(typeof(Storage)!=="undefined"){ if (localStorage.clickCount){ localStorage.clickCount=Number(localStorage.clickCount)+1; updateResults(); console.log("Added +1 to Click Count! New value: " + localStorage.clickCount); goldStarNotification(); } else{ clickCounterReset(); // Set the click-counter to 0 updateResults(); } } } function updateResults(){ var myCounter = localStorage.clickCount; document.getElementById("result").innerHTML = "You have clicked the button " + myCounter + " time(s)."; } function clickCounterReset(){ console.log("The reset was hit!"); localStorage.clickCount=0; updateResults(); } function goldStarNotification(){ if (localStorage.clickCount == 10){ console.log("You WIN!!! ZOMG!"); document.getElementById("starNotification").innerHTML = "&lt;center&gt;&lt;h1&gt;Successfully reached Level 10!&lt;/h1&gt;&lt;/center&gt;"; } } &lt;/script&gt; &lt;/HEAD&gt; &lt;BODY class="body" bgcolor="black", onLoad="clickCounterReset()"&gt; &lt;br&gt; &lt;br&gt; &lt;div id="starNotification" style="color: white;"&gt;&lt;/div&gt; &lt;br&gt; &lt;br&gt; &lt;center&gt; &lt;div class="noLight"&gt; &lt;div class="pointlessbutton" style="cursor: pointer;" onClick="clickCounter()"&gt; &lt;font color="white" size="4"&gt;+1&lt;/font&gt; &lt;/div&gt; &lt;br&gt; &lt;div class="pointlessbutton" style="cursor: pointer;" onClick="clickCounterReset()"&gt; &lt;font color="white" size="4"&gt;Reset&lt;/font&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="result" style="color: white;"&gt;Hey! Update me! :-)&lt;/div&gt; &lt;/center&gt; &lt;/BODY&gt; &lt;/HTML&gt; </code></pre>
 

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