Saving the value of a function that adds values to the counter every second in the clicker game

I have a mini-game clicker on JS that saves the number of coins and upgrades to the number of coins per click via localStorage. But I can’t make a save with a coin upgrade per second in any way. I would be very grateful if you could help me with this, thank you in advance! I’m attaching the code



//                                           ============= GLOBAL VARIABLES =============

var money = parseInt(localStorage.getItem('moneys')),//global player's money
    clickGain = 1,//money gain on clicker clicked =
    autoGain = 1,//parseInt(localStorage.getItem('autoGains')),//auto money gain
    interval;//auto money interval
    
if (clickGain >= 1){
        clickGain = parseInt(localStorage.getItem('clickGains'));
    }




// HTML MAIN ELEMENTS (except  shop buttons)
var element = {
    clicker   : document.getElementById("main-clicker"),//button
    money     : document.getElementById("money"),//txt
}

//                                          ============= GLOBAL FUNCTIONS =============

function addMoney() { // onClicker pressed add ClickGain
  money = money + clickGain;
  
  
  localStorage.setItem('moneys', money);
  localStorage.setItem('clickGains', clickGain);
  localStorage.setItem('autoGains', autoGain);
}

function updateMoney(check=true) {//update html money txt
  text = "JUMPS: " + money;
  element.money.innerHTML = text;
  if(check){checkPrices();}
  
/*if (autoGain >= 1){
        autoGain = parseInt(localStorage.getItem('autoGains'));
    }*/

}
function autoMoney(amount) {//auto add money every interval
  clearInterval(interval);
  interval = setInterval(function(){ money = money + autoGain; updateMoney(); }, 200 / amount);
}

//called when a shop Element was bought
function checkPrices() {
    //Check price for each shop element
    //unlock purchase button if enough money
    for(let i=0;i<shop.length;i++){
        if(money >= shop[i].price){
            shop[i].element.disabled = false;
        }
    }
}
//called when a shop Element was bought
function onBuy(obj) {
    //update money
    money -= obj.price;
    updateMoney(check=false);
    //localStorage.setItem('moneys', money);
    //localStorage.setItem('clickGain', clickGain);
    //localStorage.setItem('autoGain', autoGain);
    //lock every purchase buttons in shop
    for(let i=0;i<shop.length;i++){
        shop[i].element.disabled = true;
    }
}

//                                       ============= SHOP BUTTON CLASS =============

class ShopElement{
    // Object for elements in the shop.
    // New Instance Token:
    //   id -> html main element id (in Html)
    //   newprice_func -> the new price formula function
    //   onclick_func  -> the onClick function
    
    constructor (id,newprice_func,onclick_func) 
    { //constructor: called on "new ShopElement()"
        this.id = id;
        this.element = document.getElementById(id);
        this.element.onclick = this.purchase.bind(this);
        this.text_element = this.element.getElementsByTagName("b")[0];
        
        this._updatePrice = newprice_func;
        this._onClick = onclick_func;
        
        this.price = 0;
        this.purchaseLvl = 1;
        this.updatePrice();
    }
    
    //Call default functions with this as argument
    onClick(){this._onClick(this);}
    updatePrice(){this._updatePrice(this);}
    
    //Update Button's txt price
    updateText(){
        this.text_element.innerHTML = "<b>" +'$'+this.price+': ' + "</b>";}
    
    // Update Every new purchase
    update(){
        this.updatePrice(); //calculate new price
        this.updateText();  //update displayed txt
    }
    // called on Element clicked
    purchase(){
        this.purchaseLvl += 1;
        this.onClick();
        onBuy(this);
        this.update()
        checkPrices();
    }
    
}

//                                   =============== SHOP BUTTONS & FUNCTIONS ===============

//alls buttons functions ( newPriceFormula , onClick )
function newPrice1(obj){obj.price = clickGain * 25 * obj.purchaseLvl;}
function newPrice2(obj){obj.price = 250 * obj.purchaseLvl;}
function newPrice3(obj){obj.price = autoGain * 30 * obj.purchaseLvl + 900;}
function newPrice4(obj){obj.price = clickGain * 25 * obj.purchaseLvl;}
function newPrice5(obj){obj.price = clickGain * 550 * obj.purchaseLvl;}
function onClick1(obj){clickGain*=2;}
function onClick2(obj){autoMoney(this.purchaseLvl);}
function onClick3(obj){autoGain*=2;}
function onClick4(obj){clickGain*=2;}
function onClick5(obj){clickGain*=5;}



//all shop's buttons
shop = [
    //new ShopElement("b1",newPrice1,onClick1),
    new ShopElement("b2",newPrice2,onClick2),
    new ShopElement("b3",newPrice3,onClick3),
    new ShopElement("b4",newPrice4,onClick4),
    new ShopElement("b5",newPrice5,onClick5),
    
    //new ShopElement("b4",newPrice4,onClick3),
];

//                                           ================= START =================

// FIRST UPDATE (on page loaded)
updateMoney(); //money txt
for (let i=0;i<shop.length;i++){
    shop[i].update() //buttons txt & price
}

//set main clicker function onClick
element.clicker.onclick = function() { 
    element.clicker.disabled = true;
    addMoney(); updateMoney(); 
    element.clicker.disabled = false;
};



I tried to use localStorage with both the money and clickGain variables, but without success

New contributor

YORIK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật