js/index.js
//buy produce, update cash, cost and hold info if good sale
buy produce, update cash, cost and hold info if good sale
buy produce update cash cost and hold info if good sale
function buyCargo(stock) {
  if (cargo.length < maxCargo && cash >= portInfo[nowPort][stock]){
    if (portInfo[nowPort][stock] > 0){
      cash -= portInfo[nowPort][stock];
      document.getElementById("cash").innerHTML = "$" + cash;
      cargo[cargo.length] = stock;
      portInfo[nowPort][stock] = Math.round(portInfo[nowPort][stock]*(Math.random()*15+100)/100);
      listCargo();
      listPort();
    } else {
      alert("sorry out of stock");
    }
  } else {
    if (cargo.length >= maxCargo){
      alert("You don't have enough hold for more cargo. \n Sell some cargo to make room.");
    } else {
      alert("You don't have enough cash for " + cargoList[stock] + " here.");
    }
  }
}
function buyCargo ( stock ) { if ( cargo . length < maxCargo && cash >= portInfo [ nowPort ] [ stock ] ) { if ( portInfo [ nowPort ] [ stock ] > 0 ) { cash -= portInfo [ nowPort ] [ stock ] ; document . getElementById ( "cash" ) . innerHTML = "$" + cash ; cargo [ cargo . length ] = stock ; portInfo [ nowPort ] [ stock ] = Math . round ( portInfo [ nowPort ] [ stock ] * ( Math . random ( ) * 15 + 100 ) / 100 ) ; listCargo ( ) ; listPort ( ) ; } else { alert ( "sorry out of stock" ) ; } } else { if ( cargo . length >= maxCargo ) { alert ( "You don't have enough hold for more cargo. \n Sell some cargo to make room." ) ; } else { alert ( "You don't have enough cash for " + cargoList [ stock ] + " here." ) ; } } }
buy produce, update cash, cost and hold info if good sale
buy produce update cash cost and hold info if good sale
//price will rise 1-14% //show error can not buy