---
id: 698a1a73ade5ac0e19180fa3
title: "Challenge 200: Letter and Number Count"
challengeType: 28
dashedName: challenge-200
---

# --description--

Given a string, return a message with the count of how many letters and numbers it contains.

- Letters are `A-Z` and `a-z`.
- Numbers are `0-9`.
- Ignore all other characters.

Return `"The string has X letters and Y numbers."`, where `"X"` is the count of letters and `"Y"` is the count of numbers. If either count is 1, use the singular form for that item. E.g: `"1 letter"` instead of `"1 letters"` and `"1 number"` instead of `"1 numbers"`.

# --hints--

`countLettersAndNumbers("helloworld123")` should return `"The string has 10 letters and 3 numbers."`.

```js
assert.equal(countLettersAndNumbers("helloworld123"), "The string has 10 letters and 3 numbers.");
```

`countLettersAndNumbers("Catch 22")` should return `"The string has 5 letters and 2 numbers."`.

```js
assert.equal(countLettersAndNumbers("Catch 22"), "The string has 5 letters and 2 numbers.");
```

`countLettersAndNumbers("A1!")` should return `"The string has 1 letter and 1 number."`.

```js
assert.equal(countLettersAndNumbers("A1!"), "The string has 1 letter and 1 number.");
```

`countLettersAndNumbers("12345")` should return `"The string has 0 letters and 5 numbers."`.

```js
assert.equal(countLettersAndNumbers("12345"), "The string has 0 letters and 5 numbers.");
```

`countLettersAndNumbers("password")` should return `"The string has 8 letters and 0 numbers."`.

```js
assert.equal(countLettersAndNumbers("password"), "The string has 8 letters and 0 numbers.");
```

# --seed--

## --seed-contents--

```js
function countLettersAndNumbers(str) {

  return str;
}
```

# --solutions--

```js
function countLettersAndNumbers(str) {
  let letterCount = 0;
  let numberCount = 0;

  for (let char of str) {
    if ((char >= 'A' && char <= 'Z') || (char >= 'a' && char <= 'z')) {
      letterCount++;
    } else if (char >= '0' && char <= '9') {
      numberCount++;
    }
  }

  const letterWord = letterCount === 1 ? "letter" : "letters";
  const numberWord = numberCount === 1 ? "number" : "numbers";

  return `The string has ${letterCount} ${letterWord} and ${numberCount} ${numberWord}.`;
}
```
