SnakesBite101 Posted April 1, 2013 Share Posted April 1, 2013 I understand how Ternary operators work but i came across an inline one and im trying hard to figure out what each operation is doing. Can anyone please explain this to me: var hadRelations = false,isSure = false, presidentQuote = hadRelations ? "Did not have relations" : isSure ? "Did not have relations" : "I admit"; "I admit" is the value returned 1st i dont understand why they use "," instead of ";" to terminate variable definitions. But what is the Ternary doing? i don't understand the use of the first two strings in the operation. What is the concept here, what would make the return value equal to either of the first two strings, instead of the last one? Thanks Link to comment Share on other sites More sharing options...
davej Posted April 1, 2013 Share Posted April 1, 2013 You can sayvar a;var b;var c;or you can sayvar a,b,c;or you can sayvar a, b, c; forvar answer = x ? y : z; if x is true then answer = yif x is false then answer = z forvar answer = x ? y : z ? a : b if x is true then answer = yif x is false and z is true then answer = aif x is false and z is false then answer = b Link to comment Share on other sites More sharing options...
SnakesBite101 Posted April 1, 2013 Author Share Posted April 1, 2013 i understand now.. thanks:) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now