user
Write a response that appropriately completes the request.

### Instruction:
Write a JavaScript function that takes in a string and returns an object with each character of the string as a key, and the number of times that character appears in the string as the value.

### Response:
assistant
"""
Function to count character frequency in a string
"""

function countCharacterFrequency(string) {
    let freqObj = {};
    for (let c of string) {
        if (freqObj[c]) {
            freqObj[c]++;
        } else {
            freqObj[c] = 1;
        }
    }
    return freqObj;
}

if __name__ == '__main__':
    str = "hello world";
    console.log(countCharacterFrequency(str)); 
    // Output: { h: 1, e: 1, l: 3, o: 2, w: 1, r: 1, d: 1 }