Problem with LocalStorage

0

I have a problem with my code:

var llistaColors = ["grey", "black", "blue", "yellow","red","purple", "green", "white", "orange", "pink"];
var llistaNomColors =["Gris", "negre", "blau", "Groc", "Vermell", "lila", "Verd", "blanc", "Taronja", "rosa"];


function iniColors(){
	for (i=0; i<llistaColors.length;i++){
    pintaColors(i, llistaColors[i]);

	}
}

function mouColorsEsquerra(){	
		llistaColors.unshift(llistaColors.pop());
		llistaNomColors.unshift(llistaNomColors.pop());	
		updateColorName(llistaNomColors[0]);
		iniColors();
		desaPrimerColor();
}

function pintaColors(i, color){
		var colorDivs = document.querySelectorAll('.colordiv');
    colorDivs[i].style.backgroundColor = color;
}

function updateColorName(name){
		var currentColor = document.getElementById('primerColor');
    currentColor.textContent = name;
}	
 
 
  function desaPrimerColor(){
	 localStorage.setItem("color", "primerColor");

  }
  
  function recuperaPrimerColor(){
	 var color = localStorage.getItem("primerColor");
	

  } 
 
document.addEventListener('DOMContentLoaded', function() {
	var btnRotate = document.getElementById('brotar1');
	//btnRotate.addEventListener('click', mouColorsEsquerra);
 
});

The problem points out to me in the next part:

  function desaPrimerColor(){
    	 localStorage.setItem("color", "primerColor");

      }

Tells me "Unknown error"

It has to be simple but I do not clarify anything ..

I have to have two functions.

The first is to say the function DesaPrimerColor () keeps the last color of the rotation. That is to say when we close the explorer must have kept in what color I have stayed ..

The second is to say the function RecoverFirstColor () You have to return it when you restart Windows ...

But I can not get out because I do not know where I'm wrong ..

Haber if you can help me ..: (

    
asked by Montse Mkd 16.03.2017 в 20:00
source

1 answer

0

I have already solved I think about saving ... now I have the problem in recovering .. I do not know how to do it ..

var llistaColors = ["grey", "black", "blue", "yellow","red","purple", "green", "white", "orange", "pink"];
var llistaNomColors =["Gris", "negre", "blau", "Groc", "Vermell", "lila", "Verd", "blanc", "Taronja", "rosa"];


function iniColors(){
	for (i=0; i<llistaColors.length;i++){
    pintaColors(i, llistaColors[i]);
	updateColorName(llistaNomColors[0]);
	
		
		}
}

function mouColorsEsquerra(){	
		llistaColors.unshift(llistaColors.pop());
		llistaNomColors.unshift(llistaNomColors.pop());	
		updateColorName(llistaNomColors[0]);
		iniColors();
		
		
}

function pintaColors(i, color){
		var colorDivs = document.querySelectorAll('.colordiv');
    colorDivs[i].style.backgroundColor = color;
}

function updateColorName(name){
		var currentColor = document.getElementById('primerColor');
    currentColor.textContent = name;
}	
 
  function desaPrimerColor(){
	 localStorage.setItem("color", llistaNomColors[0]);

  }
  
  function recuperaPrimerColor(color){
	 var color1 = localStorage.getItem(llistaNomColors[0]);
  }
	
    
answered by 16.03.2017 в 20:29