Replacing Class Background Color based on inner text

Just can’t figure out why this code won’t work.
I’m trying to replace the background colour of a class based on the inner text of the document.

I don’t have an Id to connect to so I have to search for class.

    <script> 
if (window.location.href.startsWith('https://mytestsite.com.au/')) {
if (( document.documentElement.innerText).indexOf('API') > -1) {
    document.getElementsByClassName('training-card__name').style.backgroundColor = "red";
}
}
</script>

Help appreciated.