-5

X=(x=== images.length-1) ? 0 : x+ 1;

Please help me I have no idea, and it's for a school task that I have to hand in.

Mona.V
  • 1
  • 2
  • 4
    Do they teach researching in the school at all? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator – Teemu Nov 07 '16 at 17:43
  • Good idea to read up on ternary statements if it's for school, you never know when you might need them in the future. – MCMXCII Nov 07 '16 at 17:43
  • 1
    Possible duplicate of [Question Mark in JavaScript](http://stackoverflow.com/questions/1771786/question-mark-in-javascript) – VLAZ Nov 07 '16 at 17:46
  • 4
    It means the author didn't realize they could use the [remainder operator](http://www.ecma-international.org/ecma-262/7.0/index.html#sec-applying-the-mod-operator) for that: `x = (x + 1) % images.length;` – T.J. Crowder Nov 07 '16 at 17:46
  • the title of [this question](http://stackoverflow.com/questions/4168981/what-does-mean-in-javascript) seems to be more on point it's marked as a dupe to something not-as-helpful. – VLAZ Nov 07 '16 at 17:47

1 Answers1

0

I'm not sure why people are so opposed to just answering the question. It's a ternary operation. It's a shortcut for an if/else clause. For this particular operation,

Is x equivalent (===) to images.length-1? If so, set X to 0. Otherwise, set X to x + 1.

This pattern is likely used to endlessly iterate over an array (images). Once it reaches the end, it resets to the first element in the array.

gergi
  • 439
  • 2
  • 5
  • Thank you so much, your help is really appreciated @gergi – Mona.V Nov 07 '16 at 18:09
  • And we have answered it. There are _three_ comments that have direct links to answers. Two of them are duplicate questions. Another comment directly states this is a ternary operator. What more information is needed here? – VLAZ Nov 07 '16 at 18:13
  • I'm confused because I know the answer has been answered and I have not asked for anymore information so why does it seem like you have a problem. – Mona.V Nov 07 '16 at 18:20