Check if first letter of sentence is capital or not using Javascript

Check if first letter of sentence is capital or not

const test1 = "Lorem Ipsum is simply dummy text";
const test2 = "Lorem Ipsum Is Simply Dummy Text";

function isCapitalized(sentence) {
  return sentence.split(' ').every(word => {
      const firstLetter = word.charAt(0);
      return firstLetter.toUpperCase() === firstLetter;
  })
}

console.log(isCapitalized(test1)); // false
console.log(isCapitalized(test2)); // true

Leave a Comment

Your email address will not be published. Required fields are marked *