Pergunta

localStorage.setItem('gameState', '{"
grid ":{"
size ":4,"
cells ":[[{"
position ":{"
x ":0,"
y ":0},"
value ":1024},{"
position ":{"
x ":0,"
y ":1},"
value ":1024},{"
position ":{"
x ":0,"
y ":2},"
value ":1024},{"
position ":{"
x ":0,"
y ":3},"
value ":1024}],[{"
position ":{"
x ":1,"
y ":0},"
value ":1024},{"
position ":{"
x ":1,"
y ":1},"
value ":1024},{"
position ":{"
x ":1,"
y ":2},"
value ":1024},{"
position ":{"
x ":1,"
y ":3},"
value ":1024}],[{"
position ":{"
x ":2,"
y ":0},"
value ":1024},{"
position ":{"
x ":2,"
y ":1},"
value ":1024},{"
position ":{"
x ":2,"
y ":2},"
value ":1024},{"
position ":{"
x ":2,"
y ":3},"
value ":1024}],[{"
position ":{"
x ":3,"
y ":0},"
value ":1024},{"
position ":{"
x ":3,"
y ":1},"
value ":1024},{"
position ":{"
x ":3,"
y ":2},"
value ":1024},{"
position ":{"
x ":3,"
y ":3},"
value ":1024}]]},"
score ":272,"
over ":false,"
won ":false,"
keepPlaying ":false}');

My script is just a simple one meant to implement into the browser bar of chrome but it returns SyntaxError: Unexpected token ILLEGAL. I have tried setting the local storage to something simple and it works. Can someone tell me what is wrong or rewrite it so it works.

Foi útil?

Solução

Like mentioned in the comments, you had wrong indentation as well as some extra spaces and missing commas.

localStorage.setItem('gameState', '{"grid":{"size":4,"cells":[[{"position":{"x":0,"y":0},"value": 1024},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}}]]},"score":272,"over":false,"won":false,"keepPlaying ":false}');

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top