2
Good afternoon guys, I was playing with js today, follow my code line:
index.html
<!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>Document</title>
<script src="script.js" defer></script>
</head>
<body>
<input type="password" name="" id="senha1">
<input type="password" name="" id="senha2">
<button id="btn">verificar senha</button>
</body>
</html>
script js.
function validarSenha(){
if (senha1.value == "" || senha2.value == ""){
alert('você esqueceu uma das senhas')
} else if (senha1.value == senha2.value){
alert('as senhas são iguais');
} else {
alert('as senhas são diferentes');
}
}
btn.onclick = validarSenha;
senha1 = document.querySelector(#senha1)
senha2 = document.querySelector(#senha2)
btn = document.querySelector(#btn)
,
But when I opened the index.html my job validarSenha
worked as expected, and I was curious, because I would have to give as Undefined these variables correct ? or not, I thank you in advance for understanding with my laygirl
Hi Raphael! Your question is good, and common. I gave an answer on another question, take a look at the one I marked as duplicate.
– Sergio
thanks @Sergio gave a bug but you clareou kkkkk worth u
– Raphael Melo De Lima