Latchezar Mladenov
Posts: 0
Joined: Thu Jan 10, 2013 11:19 pm

Saving JavaScript

Hi, in my quiz game i have 4 levels with 21 questions and when I guess 21 questions of one level the app run the following javascript:

var button = document.getElementById("j_399").childNodes[0];
button.childNodes[0].innerHTML = "Level 2 - unlocked";

document.getElementById("j_399").disabled = false;

And everything runs correctly. But when I exit the app and start it again the javascript has not saved. Is there any method to save the function when I exit and start again.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Saving JavaScript

Hello,

We cannot reproduce your problem.

Does Run Javascript action disappear from the project?
Can you see other actions for this component in the editor?
Or you are able to see Action in the editor, but Javascript won't work in test?

Latchezar Mladenov
Posts: 0
Joined: Thu Jan 10, 2013 11:19 pm

Saving JavaScript

No, JavaScript run correctly when a button is clicked. I want to save the function which is clicked once for all the time not only for the resent game

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Saving JavaScript

Hello!
You can save to localStorage value (like indication that first test passed)

localStorage.setItem('test1Passed', 'true');

Then on page Load you can check whether test passed. If so - run next JS:

codevar isTest1Passed = localStorage.getItem('test1Passed');
if (isTest1Passed === "true") {
var button = document.getElementById("j_399").childNodes[0];
button.childNodes[0].innerHTML = "Level 2 - unlocked&quot

document.getElementById("j_399").disabled = false;
}/code

Return to “Issues”