var i=+(prompt("сколько всего слов ?")); while (n <= i){ var slovo=prompt(); var otvet=prompt(); n++; } a1=slovo; b1=otvet; 

How to make it so that slovo, somewhere preserved? The essence of this program is that you enter words into English and their translation, and then these English words are randomly displayed on the screen and you must write a translation.

    1 answer 1

    You can use localStorage

     localStorage.setItem('myCat', 'Tom'); //сохранить localStorage.getItem('myCat'); //взять 

    According to your example:

     var i=+(prompt("сколько всего слов ?")); while (n<=i){ var slovo=prompt(); var otvet=prompt(); localStorage.setItem(slovo, otvet); n++; } 

    And then when you call localStorage.getItem('english'); will return "English". Naturally, if it was previously introduced.

    There are more cookies . The links have examples of use.

    UPDATE by comment

    You need to add localValue to the loop body:

     var i = (prompt("сколько всего слов ?")); var n = 1; while (n <= parseInt(i)) { var slovo = prompt("Введите слова:"); var otvet = prompt("Введите перевод:"); localStorage.setItem(slovo, otvet); n++; } n1 = 1; while (n1 <= i) { var localValue = localStorage.getItem(slovo); var answer = prompt(localValue); if (answer === localValue) alert("Правильно"); n++; } 

    If you are working in Google Chrome, you can click F12 -> Application -> (on the left in the Storage section) Local Storage -> your domain. There will be data stored in your local repository. I don’t know exactly how to open Firefox, but about the same.

    • <meta charset="utf-8"> <script> var i=+(prompt("сколько всего слов ?")); n=1; while (n<=i){ var slovo=prompt("Введите слова:"); var otvet=prompt("Введите перевод:"); localStorage.setItem(slovo, otvet); n++; } var localValue = localStorage.getItem(slovo); console.log(localValue); n1=1; while (n1<=i){ var a=prompt(localValue); if (a==localValue) alert("Правильно") n++; } localStorage.removeItem(slovo) </script> <meta charset="utf-8"> <script> var i=+(prompt("сколько всего слов ?")); n=1; while (n<=i){ var slovo=prompt("Введите слова:"); var otvet=prompt("Введите перевод:"); localStorage.setItem(slovo, otvet); n++; } var localValue = localStorage.getItem(slovo); console.log(localValue); n1=1; while (n1<=i){ var a=prompt(localValue); if (a==localValue) alert("Правильно") n++; } localStorage.removeItem(slovo) </script> and how to make it so that he saved past words. Do I get it so that it saves the last words or is it through cookies? - elfir
    • You only deduce the last word, now I'll show in update - A1essandro