Q:

Write a JavaScript program that will return true if the string is y/yes or false if the string is n/no

0

Write a JavaScript program that will return true if the string is y/yes or false if the string is n/no.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const yes_No = (val, def = false) =>
  /^(y|yes)$/i.test(val) ? true : /^(n|no)$/i.test(val) ? false : def;
console.log(yes_No('Y')); 
console.log(yes_No('yes'));  
console.log(yes_No('No')); 
console.log(yes_No('Foo', true));  

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now