The console throws: index.js:5 Uncaught TypeError: Cannot read property 'length' of undefined at checkUserName. Could it have something to do with the scope?
It's worth mentioning the code works fine when I replace the condition in my if
statement by: inputEl.value.length
const inputEl = document.querySelector("input");
function checkUserName(num) {
var elMsg = document.querySelector("h1");
if(this.value.length < num) {
elMsg.textContent = "name must be at least 5 letters long";
} else {
elMsg.textContent = "word's long enough";
}
}
inputEl.addEventListener("blur", function(){
checkUserName(5)
}, false)
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Practise App</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<input type="text" name="ronal" value="">
<h1></h1>
<script src="index.js" type="text/javascript"></script>
</body>
</html>