Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
Is there a reason why this function only works once?

I am using JS-Cookie to make a simple clicker game. When I call the function, it works once, but then I have to refresh for the function to work again. I have tried adding a console.log after it to help debug it, and the log shows up, but the Cookies.set isn't working. I don't know what is happening and I'm not too familiar with this library so any help is appreciated.

Javascript

(function refreshCookies(i) {
    setTimeout(function () {
        let flame = Cookies.get('flame');
        let gems = Cookies.get('gems');
        let cuid = Cookies.get('CUID');
        let username = Cookies.get('username');
        let value = Cookies.get('value');

        let value_amount = document.getElementById('value-amount');
        let flame_amount = document.getElementById('flame-amount');
        let gem_amount = document.getElementById('gem-amount');
        let board_placing = document.getElementById('board-placing');
        let welcome_username = document.getElementById('welcome-username');
        let username_header = document.getElementById('username-header');
        let title = document.getElementById('title');

        value_amount.innerHTML = "$" + value;
        flame_amount.innerHTML = "<i class=\"fas fa-fire-alt\"></i> " + flame;
        gem_amount.innerHTML = "<i class=\"fas fa-gem\"></i> " + gems;
        welcome_username.innerHTML = "Welcome, " + username + "!";
        username_header.innerHTML = username;
        title.innerHTML = "Shoe Clicker - $" + value;
        if (--i) {
            refreshCookies(i);
        }
    }, 0500);
})(Infinity);
// clicker

function addClick() {
    Cookies.set('value', parseInt(value) + 1);
    console.log('click added!');
}

HTML

<section onclick="addClick();" class="clicker">
    <h2>Press anywhere to get money!<h2>
    <i class="fas fa-dollar-sign"></i>
</section>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Use an increment to increase the value on each click . A simple demo is in below snippet .

var money = 0
function addClick() {
  money++
  document.getElementById("demo").innerHTML = money
}
<section onclick="addClick();" class="clicker">
  <h2>Press on me to get money $ !</h2>
  <i class="fas fa-dollar-sign"></i>
</section>
<div id="demo"></div>

about 4 years ago · Juan Pablo Isaza Relatório

0

Have you tried adding something like this?

function addClick() {
    let value = Cookies.get('value');
    Cookies.set('value', parseInt(value) + 1);
    console.log('click added!');
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda