Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

121
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda