Question

I have this code:

(options.parent) ? top = options.parent.height / 2; : top = parent.height() / 2;

Because of the double slash that i use there it get's an error i know why i get the error i just don't know how to write it to work.
Thanks again.

Was it helpful?

Solution

It has nothing to do with the "double slashes", remove the semicolon

(options.parent) ? top = options.parent.height / 2 
                 :top = parent.height() / 2;

Semicolon was meant to define end of statement(optional), the ternary operator is treated as a single statement.

(options.parent) ? top = options.parent.height / 2; : top = parent.height() / 2;
//                                                ^------ Wrong!

OTHER TIPS

I think it's not the slash problem but the semicolon. Try this:

top = (options.parent ? options.parent.height : parent.height()) / 2;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top