Solved

Nested Ternary statement

Posted on 2015-02-24
5
61 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
  • 2
  • 2
5 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 250 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 250 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

816 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now