Edit: also your style code isn’t correct. The property is on the left-hand side and the value is assigned to it.
error.style.display = "block";
Just as an aside, I would recommend using classes and the classList property. It has methods on it for adding, removing, and toggling classes. Inline styles can cause issues with specificity and are not as maintainable.
Thanks @lasjorg , it worked. Now I’m adding more complexity to it though. When the input is not long enough, it should display one message, and when the input has invalid characters, it should display another. But… I broke my code again. Where have I gone wrong???
I think you may want to include a submit button which fires your corrected function.
Otherwise the error messages will appear when the page loads.
Try using just the first condition without the function, and use the value attribute in the input element. Once you obtain the correct `conditional statement, wrap a function around it. Just a thought.