Skip to the content.

3.4 Homework

function countCharacters(input) {
    var letters = (input.match(/[a-zA-Z]/g) || []).length; 
    var numbers = (input.match(/[0-9]/g) || []).length; 
    var spaces = (input.match(/ /g) || []).length; 
    var vowels = (input.match(/[aeiouAEIOU]/g) || []).length; 


    console.log("Total Letters:", letters);
    console.log("Total Numbers:", numbers);
    console.log("Total Spaces:", spaces);
    console.log("Total Vowels:", vowels);
}

def count_characters(input_string):
    letters = len(re.findall(r'[a-zA-Z]', input_string))  
    numbers = len(re.findall(r'[0-9]', input_string))    
    spaces = len(re.findall(r' ', input_string))           
    vowels = len(re.findall(r'[aeiouAEIOU]', input_string))  

    print("Total Letters:", letters)
    print("Total Numbers:", numbers)
    print("Total Spaces:", spaces)
    print("Total Vowels:", vowels)