r23712
r23712

Reputation: 587

I'm trying to write a three conditional statement

Hello I have this line right now with an if else statement and I'm trying to convert it to if else if else statement.

This is coffescript

_index = if $product.find('.dot.active').index() then 0 else 1

Any help will be appreciated.

Upvotes: 1

Views: 64

Answers (3)

PandaWood
PandaWood

Reputation: 8343

Actually, an alternative to using if that achieves the same thing, arguably clearer, would be to use the switch statement like this:

_index = switch $product.find('.dot.active').index() 
  when false then 0 
  when 1 then 2 
  else 3

Upvotes: 0

user3822547
user3822547

Reputation: 46

_index = if $product.find('.dot.active').index() then 0 else if 1 then 2 else 3

I think this is what you're looking for.

Upvotes: 2

Robert Harvey
Robert Harvey

Reputation: 180787

_index = if $product.find('.dot.active').index() 
   then 0 
else 
   if <some other condition> then <some other result> else <yet another result>

Upvotes: 3

Related Questions