• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 67
  • Last Modified:

Nested Ternary statement

Hi
Where have I gone wrong on this?

(arrays[act][i][3]) == 0 ? image_loc + bike : ((Math.round(arrays[act][i][3]) < 5) ? image_loc + image_low : ((Math.round(arrays[act][i][3]) > 10) ? image_loc + image_high : image_loc + image_med))

Open in new window


The logic should be
if value is zero then show bike image, if not then if value is less than 5 then show image_low, if value is higher than 10 show image_high otherwise show image_med

thanks
0
lz7cjc
Asked:
lz7cjc
  • 2
  • 2
2 Solutions
 
Rainer JeschorCommented:
Hi,
what is the error? Can you ensure that in
arrays[act][i][3]

Open in new window

 you have a number (and not a string)?
HTH
Rainer
0
 
Tom BeckCommented:
Assuming integers result (what Rainer said). The statement should be assigned to a variable and you have some parenthesis out of place.
var img = (arrays[act][i][3] == 0) ? image_loc + bike : (Math.round(arrays[act][i][3]) < 5) ? image_loc + image_low : (Math.round(arrays[act][i][3]) > 10) ? image_loc + image_high : image_loc + image_med;

Open in new window

0
 
lz7cjcAuthor Commented:
it was both of those things! all sorted now
are you happy to split the points?
0
 
Tom BeckCommented:
Fine by me.
0
 
Rainer JeschorCommented:
With me as well
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now