Вместо 2 мне выдаёт 11. Потом 111, 1111 и т.д. Как исправить?
Код:
var p1= 10;
var p2 = 100;
var p3 = 500;
var p4= 1000;
var s = false;
var score = 0;
var bonus = 0;
var loading = true;
function pre_load() {
document.getElementById('xy').innerHTML = "XY: " + score;
alert(score);
alert(bonus);
}
function save() {
if(localStorage) {
localStorage.setItem('score', score);
localStorage.setItem('bonus', bonus);
}
}
function load() {
if(loading = true) {
if(localStorage) {
if(localStorage.getItem('score') > 0) {
score = localStorage.getItem('score');
}
else {score = 0;}
if (localStorage.getItem('bonus') > 0)
{bonus = localStorage.getItem('bonus');}
else {
bonus = 1;
save();}
}
pre_load();
}
}
function click_main() {
score = score + bonus;
save();
document.getElementById('xy').innerHTML('id');
function Magaz() {
var val = document.getElementById('mag').value;
var object = document.getElementById('shop');
if (val == "Открыть") {
document.getElementById('mag').value = "Закрыть";
object.style.display == 'block' ? object.style.display = 'none' : object.style.display = 'block';
}
if (val == "Закрыть") {
document.getElementById('mag').value = "Открыть";
object.style.display == 'none' ? object.style.display = 'block' : object.style.display = 'none';
}
}