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

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

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