Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ // Initialize chart
+ const ctx = document.getElementById('comparison-chart').getContext('2d');
+ let chart = createComparisonChart(ctx);
+
+ // Setup event listeners
+ setupCalculator();
+ updateIndicators();
+
+ // Update displays initially
+ updateResults();
+ });
+
+ function createComparisonChart(ctx) {
+ const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
+ const cryptoData = generateRandomData(12, 30000, 60000);
+ const goldData = generateRandomData(12, 1500, 2000);
+
+ return new Chart(ctx, {
+ type: 'line',
+ data: {
+ labels: months,
+ datasets: [{
+ label: 'Cryptocurrency (BTC)',
+ data: cryptoData,
+ borderColor: '#f4b942',
+ tension: 0.4
+ }, {
+ label: 'Gold (per oz)',
+ data: goldData,
+ borderColor: '#2a3b4c',
+ tension: 0.4
+ }]
+ },
+ options: {
+ responsive: true,
+ maintainAspectRatio: false
+ }
+ });
+ }
+
+ function generateRandomData(points, min, max) {
+ return Array.from({length: points}, () =>
+ Math.floor(Math.random() * (max - min + 1)) + min
+ );
+ }
+
+ function setupCalculator() {
+ const timeHorizon = document.getElementById('time-horizon');
+ const yearsDisplay = document.getElementById('years-display');
+
+ timeHorizon.addEventListener('input', (e) => {
+ yearsDisplay.textContent = `${e.target.value} years`;
+ updateResults();
+ });
+
+ document.getElementById('investment-amount').addEventListener('input', updateResults);
+ document.getElementById('risk-tolerance').addEventListener('change', updateResults);
+ }
+
+ function updateResults() {
+ const amount = parseFloat(document.getElementById('investment-amount').value);
+ const years = parseInt(document.getElementById('time-horizon').value);
+ const risk = document.getElementById('risk-tolerance').value;
+
+ const cryptoResult = calculatePrediction(amount, years, risk, 'crypto');
+ const goldResult = calculatePrediction(amount, years, risk, 'gold');
+
+ document.querySelector('#crypto-result .prediction').textContent =
+ `Predicted Value: $${cryptoResult.toLocaleString()}`;
+ document.querySelector('#gold-result .prediction').textContent =
+ `Predicted Value: $${goldResult.toLocaleString()}`;
+ }
+
+ function calculatePrediction(amount, years, risk, type) {
+ const rateMap = {
+ crypto: {
+ low: 0.15,
+ medium: 0.25,
+ high: 0.40
+ },
+ gold: {
+ low: 0.05,
+ medium: 0.08,
+ high: 0.12
+ }
+ };
+
+ const rate = rateMap[type][risk];
+ return Math.round(amount * Math.pow(1 + rate, years));
+ }
+
+ function updateIndicators() {
+ const indicators = {
+ volatility: {
+ crypto: 0.85,
+ gold: 0.35
+ },
+ growth: {
+ crypto: 0.75,
+ gold: 0.45
+ },
+ risk: {
+ crypto: 0.90,
+ gold: 0.30
+ }
+ };
+
+ Object.keys(indicators).forEach(type => {
+ updateIndicator(`${type}-indicator`, indicators[type]);
+ });
+ }
+
+ function updateIndicator(elementId, values) {
+ const element = document.getElementById(elementId);
+ const maxHeight = 100;
+
+ const cryptoHeight = values.crypto * maxHeight;
+ const goldHeight = values.gold * maxHeight;
+
+ element.innerHTML = `
+ `;
+ }
+
+ // Add smooth scrolling for navigation links
+ document.querySelectorAll('a[href^="#"]').forEach(anchor => {
+ anchor.addEventListener('click', function (e) {
+ e.preventDefault();
+ document.querySelector(this.getAttribute('href')).scrollIntoView({
+ behavior: 'smooth'
+ });
+ });
+ });