What’s wrong with the piece of JS Code to toggle between classes?

I want to use JavaScript code to toggle between two classes.

What’s wrong with this code that I finally got:

<script>
function tog() {
    var para = document.querySelector(".tn, .on");

    if(para.classList.contains("tn")) {
        para.classList.remove("tn");
        para.classList.add("on");
    }
    else if (para.classList.contains("on")) {
        para.classList.remove("on");
        para.classList.add("tn");

    }
}
</script>