?
Solved

Nested Ternary statement

Posted on 2015-02-24
5
Medium Priority
?
65 Views
Last Modified: 2015-02-24
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
Comment
Question by:lz7cjc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 1000 total points
ID: 40627896
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
 
LVL 38

Assisted Solution

by:Tom Beck
Tom Beck earned 1000 total points
ID: 40627901
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
 

Author Comment

by:lz7cjc
ID: 40627942
it was both of those things! all sorted now
are you happy to split the points?
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 40627976
Fine by me.
0
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 40627988
With me as well
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question