Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/691b559495c5cb5a37b9b488.md
T
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.6 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
691b559495c5cb5a37b9b488 Challenge 128: Consonant Count 28 challenge-128

--description--

Given a string and a target number, determine whether the string contains exactly the target number of consonants.

  • Consonants are all alphabetic characters except "a", "e", "i", "o", and "u" in any case.
  • Ignore digits, punctuation, spaces, and other non-letter characters when counting.

--hints--

hasConsonantCount("helloworld", 7) should return true.

assert.isTrue(hasConsonantCount("helloworld", 7));

hasConsonantCount("eieio", 5) should return false.

assert.isFalse(hasConsonantCount("eieio", 5));

hasConsonantCount("freeCodeCamp Rocks!", 11) should return true.

assert.isTrue(hasConsonantCount("freeCodeCamp Rocks!", 11));

hasConsonantCount("Th3 Qu!ck Br0wn F0x Jump5 0ver Th3 L@zy D0g.", 24) should return false.

assert.isFalse(
  hasConsonantCount("Th3 Qu!ck Br0wn F0x Jump5 0ver Th3 L@zy D0g.", 24)
);

hasConsonantCount("Th3 Qu!ck Br0wn F0x Jump5 0ver Th3 L@zy D0g.", 23) should return true.

assert.isTrue(
  hasConsonantCount("Th3 Qu!ck Br0wn F0x Jump5 0ver Th3 L@zy D0g.", 23)
);

--seed--

--seed-contents--

function hasConsonantCount(text, target) {
  return text;
}

--solutions--

function hasConsonantCount(text, target) {
  const vowels = new Set(["a", "e", "i", "o", "u"]);
  let count = 0;

  for (const char of text.toLowerCase()) {
    if (/[a-z]/.test(char) && !vowels.has(char)) {
      count++;
    }
  }

  return count === target;
}