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

188
Visualizações
Game where two players have to try to guess a random number

I wanted to create a game where two players have to try to guess a random number. Here's the code i tried to use:

const player1 = '87'
const player2 = '55'

const randomNumber = '55' //Math.floor(Math.random() * 100 + 1)

console.log('Player 1:', player1)
console.log('Player 2:', player2)

if(randomNumber != player1 || randomNumber != player2){ //if no one guessed the number
  console.log('No one guessed the random number which is', randomNumber)
} else { //if someone guessed the number
  console.log('The random number is', randomNumber)
}

Normally the const randomNumber should be the comment but to try if it works i put '55' which is the same number as the const player2, which is the Player 2 attempt to guess the number, so it should console.log the part where i commented //if someone guessed the number but somehow this code always console.log the part where i commented //if no one guessed the number

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

0

    const player1 = '87'
    const player2 = '55'
    
    const randomNumber = '87' //Math.floor(Math.random() * 100 + 1)
    
    console.log('Player 1:', player1)
    console.log('Player 2:', player2)
    
    if(randomNumber !== player1 && randomNumber !== player2){ //if no one guessed the number
      console.log('No one guessed the random number which is', randomNumber)
    } else { //if someone guessed the number
      console.log('The random number is', randomNumber ,"Guessed by player : ",randomNumber === player1?"Player 1":"Player 2")
    }

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