my error-state styling isn’t being used and i can’t figure out why

I’m working on a web based calculator using Python and Flask. I have a HTML, CSS, and JS file for the styling, and I ran into an issue. I have an info-box that has a start-state and error-state.

start-state: This is the default state that the info box should be in. The default text is ‘Enter value(s) below and select an operation.’ If I make a calculation such as 1 + 1 = 2, that whole thing will print out in the info box (1 + 1 = 2). If I hit the clear button, it will change the info-box back to its default state where it prints ‘Enter value(s) below and select an operation.’

error-state: This is the state if the user enters an invalid answer (1 + two instead of 1 + 2 etc) and it would print out the text “Invalid Input” and also change the color of the info-box to red.

I tried to google and ask around, but I still can’t figure out why my error-state isn’t properly changing the background color to red.

Here is my code so far:

<!DOCTYPE html>
<html>
<head>
    <title>Calculator</title>
      <style>
        .info-box {
            background-color: #FFECD7;
            color: #000000;
            border: 1px solid #000000;
            padding: 10px;
            margin: 0 auto 20px;
            max-width: 520px;
        }
        .start-state {
        background-color: #FFECD7;
        color: #000000;
        }
        .error-state {
         background-color: #B70F0A;
         color: #FFFFFF;
            }
        .container {
            text-align: center;
        }
        .calculator-form {
            display: inline-block;
            text-align: left;
            margin-bottom: 20px;
        }
        .section-text {
         background-color: #EBEBEB;
         color: #000000;
            padding: 10px;
        }
        .clear-button {
            width: 250px;
            height: 30px;
            background-color: #EBEBEB;
            color: #000000;
            margin-bottom: 10px;
            font-size: 15px;
        }
        label {
            font-size: 15px;
            width: 150px;
            height: 50px;
        }
        .operation-lists {
            text-align: center;
        }
        .operation-list {
            display: inline-block;
            vertical-align: top;
            margin-right: 20px;
            padding: 0;
            text-align: left;
            list-style-type: none;
        }
        .error-message {
            color: red;
        }
        .operator-button {
            width: 250px;
            height: 30px;
            background-color: #EBEBEB;
            color: #000000;
            margin-bottom: 10px;
            font-size: 15px;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>Calculator</h1>
    <div id="info-box" class="info-box start-state">
        Enter value(s) below and select an operation.
    </div>
    <div class="calculator-form">
        <form id="calculator-form" action="/calculate" method="POST">
            <label for="num1">Input A:</label>
            <input type="text" name="num1" id="num1" placeholder="0" required>
            <label for="num2">Input B:</label>
            <input type="text" name="num2" id="num2" placeholder="0">
        </form>
    </div>

    <div class="operation-lists">
        <ul class="operation-list">
            <h2 class="section-text">A and B</h2>
            <li><button class="operator-button" onclick="calculate('+')">A + B</button></li>
            <li><button class="operator-button" onclick="calculate('-')">A - B</button></li>
            <li><button class="operator-button" onclick="calculate('*')">A * B</button></li>
            <li><button class="operator-button" onclick="calculate('/')">A / B</button></li>
            <li><button class="operator-button" onclick="calculate('equals')">A == B</button></li>
            <li><button class="operator-button" onclick="calculate('power')">A ^ B</button></li>
            <li><button class="operator-button" onclick="calculate('log')">A log B</button></li>
            <li><button class="operator-button" onclick="calculate('root')">A root B</button></li>
        </ul>
        <ul class="operation-list">
            <h2 class="section-text">A only</h2>
            <li><button class="operator-button" onclick="calculate('factorial')">A!</button></li>
            <li><button class="operator-button" onclick="calculate('sin')">Sin A</button></li>
            <li><button class="operator-button" onclick="calculate('cos')">Cos A</button></li>
            <li><button class="operator-button" onclick="calculate('tan')">Tan A</button></li>
            <li><button class="operator-button" onclick="calculate('reciprocal')">1 / A</button></li>
        </ul>
    </div>

    <div class="calculator-form">
        <button class="clear-button" onclick="clearInputs()">Clear</button>

    </div>

    <div id="result"></div>
    <div id="error" class="error-message"></div>
</div>

<script>
    function calculate(operation) {
      var form = document.getElementById("calculator-form");
      var formData = new FormData(form);
       formData.append('operation', operation);

    fetch('/calculate', {
     method: 'POST',
     body: formData
})
  .then(response => response.text())
  .then(data => {
   var resultText = formData.get('num1') + ' ' + operation + ' ' + formData.get('num2') + ' = ' + data;
      document.getElementById('result').innerText = 'Result: ' + resultText;
      document.getElementById('error').innerText = '';
      document.getElementById('info-box').innerText = resultText;
      document.getElementById('info-box').className = 'info-box start-state';
})
    .catch(error => {
      document.getElementById('result').innerText = '';
      document.getElementById('error').innerText = 'Error: ' + error;
      document.getElementById('info-box').innerText = 'Invalid input';
      document.getElementById('info-box').className = 'info-box error-state';
});
}

function clearInputs() {
    document.getElementById('num1').value = '';
    document.getElementById('num2').value = '';
    document.getElementById('result').innerText = '';
    document.getElementById('error').innerText = '';
    document.getElementById('info-box').innerText = 'Enter value(s) below and select an operation.';
    document.getElementById('info-box').classList.remove('error-state');
}
</script>

This is my project, any help is appreciated!

I have tried to add the background colors within the Javascript code and it didn’t change anything at all. My error-state function isn’t being used and I tried to think of ways to include it into the code, but I am stuck.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật