Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

184
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda