Hi,
First, you can use other action to set the state for the radio button, you don't need to use JS script. In the below image, I used "Set check box state on web page" and it works well for my example.

Secondly, as I know, you are using w3schools.com for trying the JS script and it does work for your JS script because w3schools.com page embedded an iframe in the page, so JS script will not work with the iframe. You can see my image in below, I copy the html content, and saved it as a html file in my computer, then I run the JS script, it works well then.

Thanks and hope it can help you.
Mike
---------------------------------
Did I answer your question? Please consider to Mark my post as a solution! to guide others