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

119
Visualizações
Why is a number logged but not a string

What I Want to Happen

I have a function called playRound() that returns a string and then increments a number. What should happen is that both of these are logged.

What is Happening Instead

When I console.log the function, only a number is logged. It seems to be one of the numbers that is being incremented. I have a separate function to find out what the numbers are after they're incremented so this isn't specifically what I'm looking for.

What I have Tried so Far

I tried creating a second function to log just the strings, but I couldn't get it to work without having to change some code on playRound().

I thought maybe there was a way to only log strings. Tried looking around the internet but I didn't find anything related to my question.

My Code

function playRound(playerSelection, computerSelection) {
            if (playerSelection === "rock" && computerSelection === "rock") {
                return "Draw!" && ties++;
            } else if (playerSelection === "rock" && computerSelection === "paper") {
                return "You lose!" && compScore++;
            } else if (playerSelection === "rock" && computerSelection === "scissors") {
                return "You win!" && myScore++;
            } else if (playerSelection === "paper" && computerSelection === "paper") {
                return "Draw!" && ties++;
            } else if (playerSelection === "scissors" && computerSelection === "scissors") {
                return "Draw!" && ties++;
            } else if (playerSelection === "scissors" && computerSelection === "paper") {
                return "You win!" && myScore++;
            } else if (playerSelection === "scissors" && computerSelection === "rock") {
                return "You lose!" && compScore++;
            } else if (playerSelection === "paper" && computerSelection === "scissors") {
                return "You lose!" && compScore++;
            } else if (playerSelection === "paper" && computerSelection === "rock") {
                return "You win!" && myScore++;
            } else {
                return "Invalid input! Try again!" && invalidScore++;
            }
        }

        console.log("Here's the breakdown! Your Score, Computer Score, Ties, and the Invalid Score. ") + console.log(myScore, compScore, ties, invalidScore);
    } 

Please help me understand what I'm doing wrong, thank you.

about 4 years ago · Santiago Gelvez
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