Bare bones battleship game
Be careful that the random can be between 0 and 4 when it should be between 1 and 4. If you want to make it more object oriented, I would separate the interface (alert and prompt) from the game logic. As this is just a game with 1 ship, I would only do a Game and Ship objects to represent it, but for more complex versions other objects may apply. Here is how I would implement it having custom columns:

function Game(columns){
  this.guesses;
  this.guessarr;
  this.columns = columns;
  this.ship;
  this.ended;

  return this;
}

Game.prototype.getRandomNumber = function(min,max){ // interval [)
  return Math.random() * (max - min) + min;
}

Game.prototype.getRandomShipPosition = function(shipSize){
  return this.getRandomNumber(1,this.columns - shipSize + 2);
}

Game.prototype.init = function(){
  this.guesses = 0;
  this.guessarr = [];
  this.ship = new Ship(this.getRandomShipPosition(3), 3);
  this.ended = false;
}

Game.prototype.makeGuess = function(guess){
  if(isNaN(Number(guess))){
      return "Enter a valid number";
  }
  if(guess &lt;= 0 || guess &gt; this.columns){
      return "Guess has to be between 1 and " + this.columns;
  }
  if(this.guessarr.indexOf(guess) != -1){
      return "You've already entered this number. Try again";
  }
  this.guessarr.push(guess);
  if(this.ship.makeGuess(guess)){
      if(this.ship.isSunk){
          this.ended = true;
      }
      return "You got a hit!";
  }else{
      return "Miss";
  }
}

function Ship(start,size){
  this.start = start;
  this.hits = 0;
  this.size = size;
  this.isSunk = false;

  return this;
}

Ship.prototype.makeGuess = function(guess){
    if(guess &gt;= this.start &amp;&amp; guess &lt;= this.start + this.size){
        this.hits+=1;
        if(this.hits == this.size){
            this.isSunk = true;
        }
        return true;
    }
    return false;
}


var game = new Game(6);
game.init();
while(game.ended == false){
    guess = Number(prompt("Enter a guess between 1 and 6"));
    alert(game.makeGuess(guess))
}
alert("you won!")