i used beneath code for “mad-maxer-sells-out” but beside have error for missing semicolon it is not sort properly I want to know any one know why.

```
loop {
var closestGold = null;
var minGoldDist = Infinity;
var coinIndex = 0;
var i = 0;
var coins = this.findItems();
// Find the closest coin that is gold.
// Remember that gold coins have a value of 3.
if (coins){
coinSort = coins.sort (function(a, b) {
return a.distanceTo(this) - b.distanceTo(this)});
while(i < coinSort.length){
coin = coinSort[i];
i++;
if (coin.value == 3){
x = coin.pos.x;
y = coin.pos.y;
this.moveXY(x, y);
}
}
}
}
```