Cookies
How do i save game progress with cookies?
Voters
SameeraMurthy (110)
Solution
In JavaScript, you can create cookies with document.cookie
.
document.cookie = "score=10";
But if you want to use more features out of
cookies, check out
https://www.w3schools.com/js/js_cookies.asp
It also gives you some code to create a wrapper function for setting and getting cookies.
https://www.w3schools.com/js/tryit.asp?filename=tryjs_cookie_username
You can also save info with localStorage
.
https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
https://www.w3schools.com/html/html5_webstorage.asp
I would more recommend localStorage, so much easier to use, and you don't have to worry about expiration.
just like that! That's it! The value has to be a string, however.
and then to get a kei:
Number()
just converts it into a number, which is useful for us.@Coder100 so I just put both those lines in and it'll save your cookie amount?