Was working through the following problem:

function

`padIt`

accept 2 parameters:1.

`str`

, it's a string representing the string to pad, we need to pad some`"*"`

at leftside or rightside of`str`

2.

`n`

, it's a number, how many times to pad the string.

This is the answer:

```
function padIt(str,n){
var count = 0;
while ( count < n ) {
count % 2 ? str += '*' : str = '*' + str;
count ++
}
return str;
}
```

Can someone explain this part? `count % 2 ? str += '*' : str = '*' + str;`

Say I put these parameters in the function, `padIt('a', 1)`

The first loop will have `count = 0`

so the function will have `0 % 2`

which = `0`

. Why does the function choose the option `str = '*' + str`

to output `'*a'`

? Why not `str += '*'`

to output `'a*'`

?

`0 % 2`

is`0`

, as you've said, which is a falsey value. So`0 ? a : b`

chooses`b`

for the same reason`false ? a : b`

does. (Conversely, any non-zero number is truthy.)