Javascript if conditions not redirecting another page?

this code not working to redirect another page, But alert function is working, but alert redirecting not working. told me a proper solutions. this is the code

<script>
        function cap(){
          var alpha = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', '!','@','#','$','%','^','&','*','+'];
            var a = alpha[Math.floor(Math.random()*71)];
            var b = alpha[Math.floor(Math.random()*71)];
            var c = alpha[Math.floor(Math.random()*71)];
            var d = alpha[Math.floor(Math.random()*71)];
            var e = alpha[Math.floor(Math.random()*71)];
            var f = alpha[Math.floor(Math.random()*71)];
      
            var final = a+b+c+d+e+f;
            document.getElementById("capt").value=final;
        }
        function validcap(){
            var stg1 = document.getElementById('capt').value;
            var stg2 = document.getElementById('textinput').value;
            if(stg1==stg2){
                window.location='login-verify.php';
            }
            else{
                alert("Please enter a valid captcha");
            }
        }

    </script>

I tried or find process but others process not working properly. Please help