Thank you very much All! I have got it working with all your help actually. So it needed preventDefault()
which I had missing. I also took on board another advice to move my logics. Current JavaScript is below. It might still become fickle upon introducing further functionalities but so far so good ;)
let inputValidator = (val) => {
val = nameInput.value;
if (val.length > 15 || /[0-9.*+?><,#^=!:${}()|\[\]\/\\]+/g.test(val)) {
return `No numbers or special characters and no more than 15 characters allowed`;
} else {
console.log(val);
return val;
}
};
function greeting() {
questions.innerHTML = `Hi ${inputValidator()}`
}
let clickStart = () => {
okBtn.addEventListener("click", e => {
e.preventDefault();
greeting();
});
};
clickStart();