0
javascript programme to determine if account is eligible or not eligible?
i am new to javascript so any help is much appritiated - i am trying to write a javascript programme to find out if a given account number is eligible or not ? the condition will be if the given account number has number 1 and 6 in any order, it will be eligible else it will not be eligible consider this - let accountNumber = 1234567890; if case 1 and case 6 - console.log(account eligible); break default - console.log(account not eligible); kindly comment each step so to better understand of how things are working together, thanks
2 odpowiedzi
+ 2
const account = '123456abc';
const regex = /[^1-6]/; //using regex to check if the string contains an element 1-6.
if (regex.test(account)) { //this checks if the string contains a number that is not 1-6.
console.log('Not eligible');
} else {
console.log('Eligible');
}
Now change the account by the string you want. Hope this helps.
+ 1
I recommend completing sololearn’s js course