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

224
Vistas
What will happen if there are no parameters in this function?

Following a tutorial on youtube, building a rock-paper-scissors game, but they dont really explain in detail every step. So im asking you lads, why do I have to put parameters in the win function? I did not put any parameters in the lose/tie function and it's still working.

function win(user, computer) {
  userScore++;
  userScore_span.innerHTML = userScore;
  computerScore_span.innerHTML = computerScore;
  result_div.innerHTML = "You won!"
}
function lose() {
  computerScore++;
  userScore_span.innerHTML = userScore;
  computerScore_span.innerHTML = computerScore;
  result_div.innerHTML = "Computer wins!"
}
function tie() {
  result_div.innerHTML = "Game tie!"
}

function rockPaperScissors(userChoice) {
  const computerChoice = getComputerChoice()

  if (userChoice === 'paper' && computerChoice === 'rock' || 
  userChoice === 'rock' && computerChoice === 'scissors' || 
  userChoice === 'scissors' && computerChoice === 'paper') {
    win(userChoice, computerChoice)
  } else if (userChoice === computerChoice) {
    tie(userChoice, computerChoice) 
  } else {
    lose(userChoice, computerChoice)
  } 
}

bonus: does anybody know somebody who teaches people javascript but explains everything crystal clear? im struggling to make myself understand the choices I have to do when building something. thanks!!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Apparently(while we don't have the full code) the userChoice and computerChoice are global, that's why the tutorial is not caring so much for code clarity.

As an advice: we recommend each function do one and only one thing(single responsibility principle) where it uses its arguments directly and don't rely on a global mutable state to not miss things quickly.

For JS I personally recommend reading YDKJS with some help while reading from MDN, and with time and practice of everything you are learning you start to becoming better at this

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