Skip to content

Instantly share code, notes, and snippets.

@Srushtika
Last active June 11, 2020 22:00
Show Gist options
  • Save Srushtika/34b522d3b94e0560b936c1d6631dc0cc to your computer and use it in GitHub Desktop.
Save Srushtika/34b522d3b94e0560b936c1d6631dc0cc to your computer and use it in GitHub Desktop.
Code snippet 34 - For multiplayer space invaders article
let nickname = "";
let nicknameInput = document.getElementById("nickname");
function setNickname() {
localStorage.clear()
nickname = nicknameInput.value;
localStorage.setItem("nickname", nickname);
}
if(nicknameInput){
nicknameInput.addEventListener("keyup", function(event) {
event.preventDefault();
if (event.keyCode === 13) {
document.getElementById("go-span").click();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment