Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

350
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!