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?
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.