Javascript username and password matching exercise with working code and snaps
Javascript username and password matching exercise with working code and snaps
Practice exercise : Make a program where the user inputs both username and password in the form of text inputs and when he presses submit button he gets an alert saying "username and password match" or "it's a good password" if they do not match(using Javascript).
HERE IS THE WORKING CODE(JUST COPY AND PASTE IN YOUR TEXT EDITOR) :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Test Page</title>
</head>
<body>
<h1 class="header-tag" style="text-align:center; color:red;">EXERCISE</h1>
<input type="text" id="box1" value="" placeholder="USERNAME">
<input type="password" id="box2" value="" placeholder="PASSWORD">
<button onclick="box()">CLICK ME</button>
<script>
function box(){
var a = document.getElementById("box1").value;
var b = document.getElementById("box2").value;
if(a==b)
{alert("USERNAME AND PASSWORD CANNOT BE SAME");}
else {
{
alert("VERY GOOD PASSWORD");
}
}
}
</script>
</body>
</html>
Output of the Exercise :
Comments
Post a Comment
I WOULD APPRECIATE IF YOU LEAVE A COMMENT OR YOUR FEEDBACK HERE !!!