Video Fit to Width OR Height of Viewport

Hi everyone,

Trying to get this bit of javascript to work for an embedded HTML5 video. The goal is when the viewport is wider than it is tall, that the video fit to the height. When the viewport is taller than it is wide, the video should fit to the width.

Public site is here (page called “Chapter 1”):
https://preview.webflow.com/preview/zsr-all-for-nc-microsite?preview=fdfb8b7b99cc24ce3fb87b0ca1adb2c6

Javascript I found is here (first answer below question. See “Solved it myself with a javascript function…”)
https://stackoverflow.com/questions/34591338/html5-video-fit-width-or-height/34770270#34770270?newreg=ae2571a530e04ffe8584052aaaa2d112

Kinda new at calling the javascript, what am I doing wrong?

Would also be open to other ideas of achieving this besides this script. I’ve found a few things in StackOverflow but nothing is working for me.