Let's say I have this if statement:
if (
username === firstname &&
password !== fakePassword &&
givenname === lastname
) {
console.log(`Hi ${firstname}`)
}
Now I want to make the given name required if it's longer than 3 characters:
const givennameRequired = givenname.length > 3;
can I alter the if statement in a way that says "If the givennameRequired variable is true then worry about this part"
This way the console logs against two params or three depending on the validity of givennameRequired. Obviously I'm trying to avoid using an if/else and having two console logs
Aucun commentaire:
Enregistrer un commentaire