Thanks for the demo.
It seems you were passing bad strings into document.getElementById()
You were passing in something like "#bird" as the SectionC param in sceneHelper(sectionA, sectionB, sectionC).
when you called the function
sceneHelper('#section1', '#owl', '#bird');
Inside of sceneHelper() you were doing
var x = document.getElementById(sectionC + i).style.fill
and the sectionC + i expression was evaluating as "#bird1" or "#bird2" etc.
You can't pass the # into document.getElementById(), you just want to use "bird", "horse", "lion"
I've probably made the same mistake a hundred times. Without changing a bunch of code just use:
var x = document.querySelector(sectionC + i).style.fill