WapTrick360


Share Your Creativity For Wapka
Home » Wapmaster codes » Guess the number game source code


<div class="container">
    <h1>Number Guessing Game</h1>
    <p>Guess a number between 1 and 100:</p>
    <input type="text" id="guess-input" placeholder="Enter your number here">
    <button id="guess-button">Guess</button>
    <p id="result"></p>
  </div>


<style>

*{
    user-select:none;
}
body {
    background-color: #f2f2f2;
    font-family: Arial, sans-serif;
}

.container {
    width: 80%;
    margin: 0 auto;
    background-color: #fff;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0px 0px 10px #aaa;
}

input, button {
    padding: 20px;
    font-size: 20px;
    margin-top: 20px;
    border-radius: 10px;
    width: 100%;
    background-color: #f2f2f2;
    border: none;
    color: #000;
    transition: all 0.5s ease-in-out;
}

input{
    width: 90%;
}

input:focus, button:focus {
    background-color: #555;
    color: #fff;
}

#result {
    margin-top: 40px;
    font-size: 24px;
    font-weight: bold;
    text-align: center;
    padding: 20px;
    background-color: #f2f2f2;
    border-radius: 10px;
    color: #555;
}

</style>
  <script>
      
     window.onload = function(){
var numberToGuess = Math.floor(Math.random() * 100) + 1;

var input = document.getElementById("guess-input");
var button = document.getElementById("guess-button");
var result = document.getElementById("result");

var numberOfGuesses = 0;
button.addEventListener("click", function() {
  var guess = parseInt(input.value);
  
  if (guess === numberToGuess) {
    result.innerHTML = "Congratulations! You guessed the number in " + numberOfGuesses + " tries.";
  } else if (guess < numberToGuess) {
    result.innerHTML = "Too low! Guess again.";
    numberOfGuesses++;
  } else if (guess > numberToGuess) {
    result.innerHTML = "Too high! Guess again.";
    numberOfGuesses++;
  }
});
}

  </script>



Total likes [0]
For comment section please Login Or Registration Here
Recent Comments
2025 WapTrick360
Version 2.0