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

126
Visualizações
Saving a variable globaly

I am a new developer and I am trying to make a button that each user can only press once and that has a counter that saves across all users. My code so far is:

<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>replit</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
 <script>
let btn = document.createElement("button");
btn.innerHTML = "Join Kaiism";
btn.onclick = function counter() {
  document.write (x + 1);

};
document.body.appendChild(btn);
var x ;//global variable  
x = 0
document.write(x)

   </script>
  </body>
</html>

Is there a way to save the variable x and keep it the same globally so that all users can see the total time it has been pushed?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you are talking about between separate users, you are going to need to implement some form of online sync between users in order for this to work. I would recommend something like firebase, since it is very beginner friendly and for your use case will be free.

If instead you mean only users that are using the same browser and computer(which is basically just one user lol), then utilizing local storage is what you are looking for.

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