My pangram function keeps returning the boolean value "false" even when my sentence has every letter of the alphabet

My pangram function should return true when I have every letter of the alphabet and should return false when I don’t have every letter of the alphabet in the sentence that my function uses as an argument.

And if you have more efficient solution, right now I just prefer using this inefficient algorithm(assuming that a more efficient solution to my problem may exist).

The link to my code:

what’s ch? can it be every letter of the alphabet at the same time?

maybe you need to change approach…

ch is supposed to represent every character in my string.

next thing, you use toUpperCase()to give a value to ch, but all your comparisons are with lower case letters

so should I maybe change toUpperCase() to toLowerCase()

but ch is a single character at a time. So it is one single character. It can’t be all the alphabet letters at once
you do something like

let ch = "a";
if (ch == "a" && ch == "b") {
  return true;
} else {
  return false;

it will return false as a single character can’t be equal to two different characters at the same time. When you use && both comparisons need to be true for the whole statement to be true

an other issue: your loop stops at first iteration. It is checking only the first character of the string.

try looking at your code with this:

but the forloop is supposed to make it so that it traverses through every letter of the string given and my if statement is supposed to check if every letter of the alphabet is represented in my sentence.

come here and I will show you in real time, if you want:

okay , I’m there. I just signed up

I just completed this one on Codewars so here is my solution:

function isPangram(string) {
	//create a lowercase string with everything replaced except letters
	string = string.toLowerCase().replace(/[^a-z]/g, '');

	//array with letters
	let letterArray = [];

	//loop over string, if index = -1, add item to array
	for (let i = 0; i < string.length; i++) {
		if (letterArray.indexOf(string.charAt(i)) === -1) {

	//count array.length, if equal to 26, return true, otherwise false
	return letterArray.length === 26;

I have hidden your answer, if someone is trying to solve an algorithm on their own it is rude to give them the solution just like that


Thank you. I did not realize that and was just trying to help him/her out :slight_smile: