Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!