Control CanvasGroup.alpha with script

Ive been stuck on this for several hours and Im wondering if someone out there has a solution.

Basically, I want to be able to fade my canvas out a couple of seconds after it has been interacted with.
More specifically, its a health bar for my enemies. If the enemy hasnt been collided with for a couple of seconds the bar fades out after a few seconds. Once its hit it immediately turns back on. The bar is working great, but I just need control of the opacity via scripting.

Ive been trying to use CanvasGroup.alpha with GetComponent in Javascript, but Ive had trouble.

There isnt a lot of info around on this, Im starting to wonder if its the best way to go about it.
Any suggestions?
Thanks

i use this in c# but it’l work on js, try creating private field and using FindObjectofType(); if you don’t have any other CanvasGroup components