Hey guys i am trying to create a login form with html and javascript and everything is working except that i am not able to implement maximum attempts to this. It tried nested ifs and for too but didn't succeed

.In the below code i am trying to implement maximum 3 attempts of wrong username or password.
Code:
<html>
<head>
<script type="text/javascript">
function login() {
var u=document.getElementById("user").value;
var v=document.getElementById("pass").value;
var i=0;
if(i<3)
{
if (u=="admin" && v=="admin_12")
{alert("Welcome");}
else
{alert("Oops,Try Again");
i++;}}
else{alert("Maximum Attempts Over");}
}
</script>
</head>
<body>
<form>
<b>User Name </b><input type="text" id="user">
<b>Password </b><input type="password" maxlength="8" id="pass">
<p>
<input type="button" value="Login" onclick="login()">
</form>
</body>
</html>