Solved

# Nested Ternary statement

Posted on 2015-02-24
63 Views
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))
``````

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
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
• 2
• 2

LVL 44

Accepted Solution

Rainer Jeschor earned 250 total points
ID: 40627896
Hi,
what is the error? Can you ensure that in
``````arrays[act][i][3]
``````
you have a number (and not a string)?
HTH
Rainer
0

LVL 38

Assisted Solution

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;
``````
0

Author Comment

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

LVL 38

Expert Comment

ID: 40627976
Fine by me.
0

LVL 44

Expert Comment

ID: 40627988
With me as well
0

## Featured Post

Question has a verified solution.

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

### Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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
Course of the Month6 days, 6 hours left to enroll