Site icon Hip-Hop Website Design and Development

What’s wrong with the piece of JS Code? [closed]

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>