Solved

Nested Ternary statement

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

724 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