Why am I getting the error “Uncaught TypeError: Cannot read properties of null (reading ‘appendChild’)”

I am creating my first ever JS project that is a simple To-Do list. I am creating a button that will add a paragraph of the inputted text into a container using .appendChild().

let addToDoButton = document.getElementById('addToDo');
let toDoContainer = document.getElementById('toDoContainer');
let inputField = document.getElementById('inputField');

/*On click we create a paragraph and append it to toDoContainer*/
addToDoButton.addEventListener('click', function(){
    var paragraph = document.createElement('p');
    toDoContainer.appendChild(paragraph);
})
html, body {
    width: 50%;
    margin: 0 auto;
    font-family: Arial, Helvetica, sans-serif
}

.container {
    width: 360px;
}

#inputField {
    width: 300px;
    height: 46px;
    border: 1px solid black;
    outline: none;
    font-size: 25px;
    vertical-align: middle;
}

#addToDo {
    height: 50px;
    width: 50px;
    border: 1px solid black;
    vertical-align: middle;
    font-size: 30px;
}

.to-dos {
    margin-top: 25px;
}

.paragraph-styling {
    margin: 0;
    cursor: pointer;
    font-size: 20px;
}
<h1>To Do List</h1>
<div class="container">
    <input id="inputField" type="text"><button id="addToDo">+</button>
    <div class="to-dos" id="toDoContainer">
    </div>
</div>

It happens every time I press the button.

I tried tracking all the variables but that didn’t help and I also re-read all of my variable names and they seem to be correct. I also tested the button with and without text inside the textbox.