A web-based calculator for determining the value of silver coins and rounds based on current spot prices, with premium calculation functionality. Designed for precious metals investors and collectors.
Key styling features:
The calculator uses an IIFE (Immediately Invoked Function Expression) pattern with a BarterCalculator
class containing all business logic.
Constants
const CONSTANTS = {
TROY_OUNCE: 0.715, // Silver content in junk silver coins
DEFAULT_GOLD: "3000.00",
DEFAULT_SILVER: "30.40"
};
Coin Inventory
const coinInventory = {
rounds: { factor: 1/CONSTANTS.TROY_OUNCE, count: 0, value: 0, total: 0 },
halves: { factor: 0.50, count: 0, value: 0, total: 0 },
// ... other coin types
};
BarterCalculator Class
calculateCoinDistribution(spotPrice, amount, nickelIncrement = 0)
render(changeAmount = false, nickelIncrement = 0, redistribute = true)
calculatePremiumFromPrice()
calculatePriceFromPremium()
renderPremiumTable()
The calculator exposes these global methods for testing:
window.setDefaultSpot() // Sets silver spot to $28
window.fetchMetalPrices() // Placeholder for future implementation
window.calculator // Access to calculator instance
window.coinInventory // Access to current coin counts
This documentation covers the core functionality and architecture of the Silver Barter Calculator. The code is well-structured with clear separation of concerns and comprehensive commenting for maintainability.