Silver Barter Calculator Documentation

Overview

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.

Features

  • Coin Value Calculation: Calculates value of silver rounds, half-dollars, quarters, and dimes
  • Premium Analysis: Shows price premiums at different percentage levels
  • Interactive Controls: Adjust coin counts and spot prices
  • Responsive Design: Works on mobile and desktop devices
  • Persistent Settings: Remembers user preferences between sessions

Technical Implementation

HTML Structure

CSS Styles

Key styling features:

  • Responsive design with media queries
  • CSS variables for consistent theming
  • Flexbox and grid layouts
  • Interactive button states
  • Blended background image

JavaScript Architecture

The calculator uses an IIFE (Immediately Invoked Function Expression) pattern with a BarterCalculator class containing all business logic.

Core Components:

  1. Constants

    const CONSTANTS = {
      TROY_OUNCE: 0.715,  // Silver content in junk silver coins
      DEFAULT_GOLD: "3000.00",
      DEFAULT_SILVER: "30.40"
    };
    
  2. 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
    };
    
  3. BarterCalculator Class

    • Manages all calculator functionality
    • Handles user interactions
    • Performs calculations
    • Manages localStorage persistence

Key Functions

Coin Distribution Calculation

calculateCoinDistribution(spotPrice, amount, nickelIncrement = 0)
  • Distributes a target dollar amount across different coin types
  • Ensures even numbers of coins where appropriate
  • Handles incremental adjustments

Rendering Logic

render(changeAmount = false, nickelIncrement = 0, redistribute = true)
  • Updates all displayed values
  • Handles conditional rendering based on toggle states
  • Maintains UI consistency

Premium Calculations

calculatePremiumFromPrice()
calculatePriceFromPremium()
renderPremiumTable()
  • Convert between price and premium percentage
  • Generate premium analysis table
  • Support both silver and gold calculations

Usage Instructions

Basic Operation

  1. Enter current gold and silver spot prices
  2. Input target dollar amount
  3. Toggle coin types to include/exclude from calculations
  4. Adjust coin counts using +/- buttons

Premium Analysis

  1. Click "Premiums" toggle to show premium section
  2. Select product type from dropdown
  3. Enter either price or premium percentage
  4. View premium table showing range of values

Persistent Settings

  • Coin type toggles are saved between sessions
  • Metal prices are remembered
  • No login required

Technical Notes

Dependencies

  • Pure HTML/CSS/JavaScript - no external libraries
  • localStorage for persistence
  • Responsive design works on all modern browsers

Known Limitations

  • Premium calculations assume linear pricing
  • Nickel calculations have specific rounding rules
  • Mobile layout may need adjustment for very small screens

Development API

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.