Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var score = 0;
- function run(){
- var ans1 = document.getElementById("ans1").value;
- if(ans1 == "917") {
- score++; }
- setCookie("scores", score, 30);
- window.location.href = "question2.html";
- }
- //This piece of code was tied to a button that was meant to add a point if the answer was correct(The ans1 == "917"), then save the score as a cookie, and open up the next page.
- function testIt(){
- document.getElementById("result").innerHTML = getCookie("scores");
- }
- //To help test if it did work I had another button set up to replace the innerHTML of a div tag by retrieving the cookie and putting the value in place of the HTML. However when I click it, it will return just blank text found at the end return of the getCookie code provided by W3.
- function getCookie(cname) {
- var name = cname + "=";
- var decodedCookie = decodeURIComponent(document.cookie);
- var ca = decodedCookie.split(';');
- for(var i = 0; i < ca.length; i++) {
- var c = ca[i];
- while (c.charAt(0) == ' ') {
- c = c.substring(1);
- }
- if (c.indexOf(name) === 0) {
- return c.substring(name.length, c.length);
- }
- }
- return "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement