I am trying to learn JavaScript and currently stuck on a question about how would I rewrite brad's code using the split method and bug does brad have in his code? can you please help? Here is the code
function validate(phoneNumber) {
if (phoneNumber.length > 8 ||
phoneNumber.length < 7) {
return false;
}
var first = phoneNumber.substring(0,3);
var second = phoneNumber.substring(phoneNumber.length - 4);
if (isNaN(first) || isNaN(second)) {
return false;
}
if (phoneNumber.length === 8) {
return (phoneNumber.charAt(3) === "-");
}
return true;
}
var number= validate("123-6778");
console.log(number);