Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
sea battle game / prevent typing the same thing twice

such a problem is that if I enter the same number 3 times and it counts for me as a win, but I need to prohibit it so that I cannot enter the same number a second time, can you tell me how to do this?

let randomLocation = Math.floor(Math.random() * 6)
let location1 = randomLocation
let location2 = location1 + 1
let location3 = location2 + 1
let guess
let hits = 0
let guesses = 0
let isSunk = false

while (isSunk == false) {
  guess = prompt('Enter the coordonation: ')
  let secondTime = guess
  if (guess < 0 || guess > 6) {
    alert('Your number is incorrect')
  } else {
    guesses++
    if (guess == location1 || guess == location2 || guess == location3) {
      alert('SHOT')
      hits++


      if (hits == 3) {
        isSunk = true
        alert('The ship was wrecked')
      }
    } else {
      alert('you missed')
    }
  }
}
let stats = 'You wrecked from ' + guesses + ' attempts ' + ' which means you have statistics ' + (3 / guesses)
console.log(stats)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here's one way to check to see if the user has entered the same thing before. Use a Set.

let answers = new Set();
while(true) {
  let input = prompt('Enter something')
  if (input == null) break;
  if (answers.has(input)) {
    alert('You already entered that.');
  } else {
    alert('That is new!')
    answers.add(input);  // Remember this input for later.
  }
}

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda