I m trying to write a callback function but not sure if i did it right.Can you check and correct ?
`
let username = prompt("Enter your username :");
let password = prompt("Enter your password :");
const userValid = /^[a-za-z0-9_.]*$/.test(username);
const passwordValid = /^[a-za-z0-9_]*$/.test(password);
let check = () => {
if(userValid && passwordValid){
correct();
}else{
not();
}
}
let correct = () => {
let msg = new Date();
alert(`Welcome ${username}! Today is ${msg}.`);
}
let not = ()=> {
alert(`Given username and password pair is not correct.Please try again!`);
}
check(correct,not)
`
CodePudding user response:
You forgot to add the functions in as parameters to check
:
let check = (correct, not) => {
if(userValid && passwordValid){
correct();
}else{
not();
}
};