I keep getting array not defined as an error when I am trying to push guesses into an array

I am trying to push the correct guess into an array and print out how many guesses it took (in this case one, cause I’m just inputting the correct one) and then printing out what that guess was, but I am continually getting array not defined.

var guesses = [];

function do_guess() {
  let guess = Number(document.getElementById("guess").value);
  let message = document.getElementById("message");
  if (guess == num) {
    numguesses = array.length(guesses)
    message.innerHTML = "You got it! It took you " + numguesses + " tries and your guesses were " + guesses;

>Solution :

The correct way of getting the number of elements inside an array in js :


In your case it would be


Read more here

Leave a Reply