Solved

Nested Ternary statement

Posted on 2015-02-24
5
58 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now