Changed around line 1
+ // Mock data for demonstration
+ const mockStocks = [
+ { symbol: 'AAPL', name: 'Apple Inc.', price: 150.25, change: 2.5 },
+ { symbol: 'GOOGL', name: 'Alphabet Inc.', price: 2750.80, change: -1.2 },
+ { symbol: 'MSFT', name: 'Microsoft Corp.', price: 310.45, change: 1.8 },
+ { symbol: 'AMZN', name: 'Amazon.com Inc.', price: 3300.15, change: 0.9 }
+ ];
+
+ // DOM Elements
+ const trendingStocks = document.getElementById('trending-stocks');
+ const watchlistItems = document.getElementById('watchlist-items');
+ const stockSearch = document.getElementById('stock-search');
+ const addStockBtn = document.getElementById('add-stock-btn');
+ const menuToggle = document.querySelector('.menu-toggle');
+ const navLinks = document.querySelector('.nav-links');
+
+ // Mobile menu toggle
+ menuToggle.addEventListener('click', () => {
+ navLinks.classList.toggle('active');
+ });
+
+ // Initialize trending stocks
+ function initializeTrendingStocks() {
+ mockStocks.forEach(stock => {
+ const stockCard = createStockCard(stock);
+ trendingStocks.appendChild(stockCard);
+ });
+ }
+
+ // Create stock card element
+ function createStockCard(stock) {
+ const card = document.createElement('div');
+ card.className = 'market-card';
+
+ const changeColor = stock.change >= 0 ? '#00ff9d' : '#ff4d4d';
+ const changeSymbol = stock.change >= 0 ? '+' : '';
+
+ card.innerHTML = `
+
${stock.symbol}
+
$${stock.price.toFixed(2)}
+ ${changeSymbol}${stock.change}%
+
+ `;
+
+ return card;
+ }
+
+ // Add stock to watchlist
+ function addToWatchlist() {
+ const symbol = stockSearch.value.toUpperCase();
+ if (symbol) {
+ const stock = mockStocks.find(s => s.symbol === symbol);
+ if (stock) {
+ const watchlistCard = createStockCard(stock);
+ watchlistItems.appendChild(watchlistCard);
+ stockSearch.value = '';
+ }
+ }
+ }
+
+ // Event listeners
+ addStockBtn.addEventListener('click', addToWatchlist);
+ stockSearch.addEventListener('keypress', (e) => {
+ if (e.key === 'Enter') {
+ addToWatchlist();
+ }
+ });
+
+ // Real-time price updates simulation
+ function updatePrices() {
+ const cards = document.querySelectorAll('.market-card');
+ cards.forEach(card => {
+ const priceElement = card.querySelector('.price');
+ const changeElement = card.querySelector('.change');
+ if (priceElement && changeElement) {
+ const currentPrice = parseFloat(priceElement.textContent.replace('$', ''));
+ const change = (Math.random() - 0.5) * 2;
+ const newPrice = currentPrice + change;
+
+ priceElement.textContent = `$${newPrice.toFixed(2)}`;
+ changeElement.textContent = `${change >= 0 ? '+' : ''}${change.toFixed(2)}%`;
+ changeElement.style.color = change >= 0 ? '#00ff9d' : '#ff4d4d';
+ }
+ });
+ }
+
+ // Initialize
+ document.addEventListener('DOMContentLoaded', () => {
+ initializeTrendingStocks();
+ setInterval(updatePrices, 5000); // Update prices every 5 seconds
+ });