function calculateInvestment() {
    const investment = parseFloat(document.getElementById('investment').value);
    const initialPrice = parseFloat(document.getElementById('initial-price').value);
    const newPrice = parseFloat(document.getElementById('new-price').value);
    const resultElement = document.getElementById('result');

    // Reset the class before displaying a new result
    resultElement.className = '';

    if (isNaN(investment) || isNaN(initialPrice) || isNaN(newPrice) || investment <= 0 || initialPrice <= 0 || newPrice <= 0) {
        resultElement.innerHTML = "Please enter valid positive values.";
        resultElement.classList.add('neutral');
        return;
    }

    // Calculate the amount of cryptocurrency purchased
    const cryptoAmount = investment / initialPrice;

    // Calculate the new value of the investment
    const newValue = cryptoAmount * newPrice;

    // Calculate the percentage change
    const percentageChange = ((newValue - investment) / investment) * 100;
    let message = "";

    // Determine if the change is positive or negative and set the appropriate message
    if (percentageChange > 0) {
        resultElement.classList.add('positive');
        message = `<strong>Value of Investment:</strong> $${newValue.toFixed(2)}<br>
                   <strong>Percentage Gain:</strong> ${percentageChange.toFixed(2)}%`;
    } else if (percentageChange < 0) {
        resultElement.classList.add('negative');
        message = `<strong>Value of Investment:</strong> $${newValue.toFixed(2)}<br>
                   <strong>Percentage Loss:</strong> ${Math.abs(percentageChange).toFixed(2)}%`;
    } else {
        resultElement.classList.add('neutral');
        message = `<strong>Value of Investment:</strong> $${newValue.toFixed(2)}<br>
                   <strong>No Gain or Loss:</strong> 0%`;
    }

    // Display the results
    resultElement.innerHTML = message;
}
