Question: In this fiddle <http://jsfiddle.net/mjmitche/6nar4/3/>, if you drag, for example, the little blue box into the yellow box, then the big black box will turn pink. All of the 4 boxes along the left can be dragged into the boxes inside the black box. 

At the end of the fiddle, you see the code that changes the black box to pink.

However, I want to make that a ternary operator, so that if the box is black, then it turns pink, but if it's been turned pink, then I want it to go back to black. 

I know the ternary is like this

```
x ? y: z

```

So I tried this, even though I knew it wasn't probably right

```
$("#blackbox").css({'background':'pink'}); ?

    $("#blackbox").css({'background':'black'}); : 

$("#blackbox").css({'background':'pink'}); 

```

I think the first line before the question mark is causing the problem, so how to create the `if` statement?

Answer: 
I think Dan and Nicola have suitable corrected code, however you may not be clear on why the original code didn't work.

What has been called here a "ternary operator" is called a conditional operator in ECMA-262 section 11.12. It has the form:

```
LogicalORExpression ? AssignmentExpression : AssignmentExpression

```

The LogicalORExpression is evaluated and the returned value converted to Boolean (just like an expression in an if condition). If it evaluates to true, then the first AssignmentExpression is evaluated and the returned value returned, otherwise the second is evaluated and returned.

The error in the original code is the extra semi-colons that change the attempted conditional operator into a series of statements with syntax errors.
As others have correctly pointed out, the first part of the ternary needs to return `true` or `false` and in your question the return value is a jQuery object.

The problem that you may have in the comparison is that the [web color](http://en.wikipedia.org/wiki/Html_color) will be converted to RGB so you have to text for that in the ternary condition.

So with the CSS:

```
#blackbox {
    background:pink;
    width:10px;
    height:10px;
}

```

The following jQuery will flip the colour:

```
var b = $('#blackbox');
b.css('background', (b.css('backgroundColor') === 'rgb(255, 192, 203)' ? 'black' : 'pink'));

```

[**Demo**](http://jsfiddle.net/cZ25R/)