1

Why does this

var marketName = (controller.state.operation.code === 'copy')
    ? controller.state.market.targetName
    : controller.state.market.name;

$('dd.preview-step1').html(
    'Market = <i>' 
    + marketName 
    + '</i><br />Source = <i>'
    + controller.state.source.name 
    + '</i><br />Target = <i>'
    + controller.state.target.name
    +'</i>'
);

output this:

Market = blabla
Source = blabla
Target = blabla

While this

$('dd.preview-step1').html(
    'Market = <i>'
    + (controller.state.operation.code === 'copy') 
        ? controller.state.market.targetName
        : controller.state.market.name
    + '</i><br />Source = <i>'
    + controller.state.source.name
    + '</i><br />Target = <i>'
    + controller.state.target.name 
    + '</i>'
);

only outputs this:

Market = blabla

I don't get why the rest of the string after the inline ternary operator is not printed.

Thanks for help.

1

1 Answer 1

3

Because it does not know that the + is not part of it. Use () around the ternary part so the order of operations does what you want.

$('dd.preview-step1').html('Market = <i>'+ 
    ((controller.state.operation.code === 'copy') ? controller.state.market.targetName : controller.state.market.name)
     +'</i><br />Source = <i>'+ controller.state.source.name +'</i><br />Target = <i>'+ controller.state.target.name +'</i>');

See the extra ( and ) I added at the beginning and end of the second line above.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.