First of all, is it even possible to write if/else statements directly in html with onclick attribute? And if so, why is my code not working?
So this is a button. T
sweetamylase's reply is best but you may also consider:
If your onclick= assignment is enclosed in double quotes (onclick="...") then try using only single quote characters inside of those double quotes (or vice versa).
This can make things easier when you need to make assignments to the onclick event when inserting elements dynamically and having separate script functions isn't really a good option.
Example: