Jump to content

problem with ternary operator syntax.


jimfog

Recommended Posts

Below it is a code for ternary operator syntax, I cannot understand why the editor shows it as wrong:

     var url==''? var fields = ['address', 'city', 'municipality']:var fields = ['address', 'city', 'νοmunicipality','url'];        

Do you see anything wrong with the above?

Link to comment
Share on other sites

Did the error console tell you anything?

Prepending that with "var" makes the whole statement a syntax error.

 

I'd do it this way:

var fields = (url == "" ? ['address', 'city', 'municipality'] : ['address', 'city', 'νοmunicipality','url']);

If url isn't set the program will throw an error.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...