Navigate back to the homepage

How to check if a string is a pangram in JavaScript?

Infinitbility
JavaScript
May 28th, 2022 · 1 min read

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
1// Create constant array of alphabet
2const 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'];
3
4// Create a function which accept string
5function checkPangramStrings(string) {
6 // Convert string to lower case
7 string = string.toLowerCase();
8
9 // Use javascript every loop on array of alphabet
10 // Put condition on every loop which check string alphabet char or not
11 return alphabets.every(x => string.includes(x));
12}
13
14console.log(checkPangramStrings("infinitbility")); // false
15console.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 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

How to check if two strings are anagrams of each other in Javascript?

Example of check if two strings are anagrams of each other in javascript with step by step guide.

May 28th, 2022 · 1 min read

How to check if a string is equal to another string in javascript?

Example of check if a string is equal to another string in javascript with step by step guide.

May 27th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]