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

355
Visualizações
Invalid left-hand side in assignment error. Can't find the mistake

I'm trying this code in javascript. but it's giving me this error.

var x = 1;

while (x <= 20) {
  var result = (x % 3 === 0 && x % 5 === 5 = 0) ? "FizzBuzz" : (x % 3 === 0) ? "Fizz" : (x % 5 === 0) ? "Buzz" : x);
console.log(result);
}

I thought that it was due to me assigning 'x' which is a number to 'result' which was at some point a string, so I tried to replace the final 'x' with a string, same thing.

I know I can write this with normal if-else statement but I would like to know how to do it with inline conditionals

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

0

In this part of your code

 var result = (x % 3 === 0 && x % 5 === 5 = 0)

has right = 0 , this means, "Hey, you on the LEFT" receives this value, but doesn't have a regular variable to assign to it on the LEFT SIDE, so javascript understands that you want to assign 0 to a comparison, x % 3 === 0 && x % 5 === 5 and we know it's not possible because this evaluates to a boolean value (true or false), it can't be expressed: true = 0 . This is why this exception was thrown.

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