Hi Friends đź‘‹,

Welcome To Infinitbility! ❤️

Today, I’m going to show How do I check if a string is a pangram in Javascript, here I will write a custom function to check if a string is a pangram or not.

What is a pangram?

A pangram is a string that contains every letter of the English alphabet. We are required to write a JavaScript function that takes in a string as the first and the only argument and determines whether that string is a pangram or not.

Let’s start the today’s tutorial How do you check if a string is a pangram in JavaScript?

Let’s understand how we can do

  1. Create a constant array of alphabet
  2. Create a function that accepts a string
  3. Convert string to lower case
  4. Use javascript every loop on an array of alphabet
  5. Put condition on every loop which checks string alphabet char or not
// Create constant array of alphabet
const alphabets = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];

// Create a function which accept string
function checkPangramStrings(string) {
   // Convert string to lower case
   string = string.toLowerCase();
  
   // Use javascript every loop on array of alphabet
   // Put condition on every loop which check string alphabet char or not
   return alphabets.every(x => string.includes(x));
}

console.log(checkPangramStrings("infinitbility")); // false
console.log(checkPangramStrings("abcd efgh ijkl mnop qrst uvwx yz")); // true

The above program is the simplest way to check pangram, To validate our function I have passed both case string invalid and valid string, let’s check the output.

javascript, check if a string is a pangram example
javascript, check if a string is a pangram example

I hope it’s help you, All the best 👍.