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

232
Visualizações
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 Respostas
Responde à pergunta

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 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