Practice

Count Letter Function

MEDIUMProcedures & Functions7 marks

Write function CountLetter(Text, Target) that returns how many times the character Target appears in Text. The check must be case-insensitive (A and a both count).

Input: A string, then a single-character string. Output: The count.

Example:

Input:  Banana
        a
Output: 3

Sample Test Cases

Test 1: Three a/A letters
Inputs: Banana, a
Expected: 3
Test 2: Uppercase target still matches
Inputs: Banana, A
Expected: 3

Premium Question

This question needs a paid plan — upgrade, or join a class from a teacher who has one. You can read the description and sample tests, but grading is locked.

Sign in to get started