Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. var score = 0;
  2.  
  3. function run(){
  4. var ans1 = document.getElementById("ans1").value;
  5. if(ans1 == "917") {
  6. score++; }
  7. setCookie("scores", score, 30);
  8. window.location.href = "question2.html";
  9. }
  10.  
  11. //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.
  12.  
  13. function testIt(){
  14. document.getElementById("result").innerHTML = getCookie("scores");
  15. }
  16.  
  17. //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.
  18.  
  19. function getCookie(cname) {
  20. var name = cname + "=";
  21. var decodedCookie = decodeURIComponent(document.cookie);
  22. var ca = decodedCookie.split(';');
  23. for(var i = 0; i < ca.length; i++) {
  24. var c = ca[i];
  25. while (c.charAt(0) == ' ') {
  26. c = c.substring(1);
  27. }
  28. if (c.indexOf(name) === 0) {
  29. return c.substring(name.length, c.length);
  30. }
  31. }
  32. return "";
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement