How can i make a js function only run if an field linked to it has value?

I created two input fields in my html and linked them to a js function that runs when a button is clicked, the function runs even when the input fields are empty, that is what i want to fix.

I tried adding required attributes to the input elements but that did not work.