Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function saveScoreToCookie()
- {
- var scores = getAllScores();
- //set a new cookie with the same name as the previous cookie
- //which means that it overwrites the previous cookie
- //the value will be the previous values + the new value
- document.cookie = "sudokuScores=" + scores + sudokuScore + ",;";
- }
- function scoresToInt(scores)
- {
- var intScores = [];
- scores = scores.split(",");
- for (var i = 0; i < scores.length - 1; i++)
- {
- intScores[i] = parseInt(scores[i]);
- }
- return intScores;
- }
- function getAllScores()
- {
- var scoresCookie = getCookie("sudokuScores");
- //split the cookie
- //scoresCookie[0] is cookie name
- //scoresCookie[1] is the current value
- var scores = scoresCookie.split("=")[1];
- return scores;
- }
- function getCookie(name)
- {
- //get all current cookies
- var allCookies = document.cookie;
- //split the cookies into an array with ; as the delimiter
- var allCookiesArray = allCookies.split(";");
- var searchedCookie;
- //iterate through the cookies array
- for (var i = 0; i < allCookiesArray.length; i++)
- {
- //if the currently iterated cookies name is sudokuScores
- if (allCookiesArray[i].indexOf(name) > -1)
- {
- //set currentCookies to only the sudokuScores cookie
- searchedCookie = allCookiesArray[i];
- break;
- }
- }
- return searchedCookie;
- }
- function printScoresGraph(scores){
- var scores = getAllScores();
- scores = scoresToInt(scores);
- var trace = {
- x: scores.length,
- y: scores,
- mode: 'lines+markers',
- type: 'scatter'
- };
- var data = [trace];
- Plotly.newPlot('myDiv', data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement