I'm new to javascript. I'm trying to make a laser tag game to share with my friends. However, I want it to be like Kahoot It where I can enter a game PIN to take you to the right game. However, I do not know how to tell my javascript which game I want to be taken to. Here is my code:
body {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  background-color: black;
}
.logo {
  width: 50%;
  display: block;
  margin-left: auto;
  margin-right: auto;
  margin-top: 7%;
}
.codeinput {
  width: 20%;
  size: 30%;
  display: block;
  margin-left: auto;
  margin-right: auto;
}
.codeinput:focus {
  outline: none;
}
.enterbutton {
  border: none;
  background-color: #018D94;
  padding: 1% 4%;
  border-radius: 5%;
  display: block;
  margin-left: auto;
  margin-right: auto;
  margin-top: 2%;
}
.enterbutton:hover {
  background-color: #036266;
}<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <meta charset="utf-8">
  <title>Laser Tag</title>
  <link rel="stylesheet" href="css/index.css">
</head>
<body>
  <img src="img/logo.png" class="logo" alt="Laser Tag">
  <input type="text" name="" value="" placeholder="Game PIN" class="codeinput" id="codeinput">
  <button type="button" name="button" class="enterbutton" onclick="enterfunc">ENTER</button>
</body>
<script src="js/index.js" charset="utf-8"></script>
<script type="text/javascript">
  var codeinput = document.getElementById('codeinput').value;
  function enterfunc() {
    if (codeinput == '2147') {
      alert('Great! This works!');
    } else {
      alert('Hmm...something in your code is not right');
    }
  }
</script>
</html>

var codeinput = document.getElementById('codeinput').value;is read on page load. It will not magically update the variable.... Move it inside of the function.....var codeinput = document.getElementById('codeinput').value;– that would belong into your function here, so that the current value gets read, when the button gets clicked. Otherwise, you are only reading the value the field had at the time this line of code executed (and that was just empty at this time.)if(document.getElementById('codeinput').value =='2147')will give your desired outputvar codeinput = document.getElementById('codeinput');to store the element itself, then useif (codeinput.value == '2147')to read the current value inside the function.