Input value returns Null

Trying to create something a button that can get the value in an element but i keep getting the error " Cannot read property ‘value’ of null"

I did some research and found out it’s because javascript loads before the HTML elements but from my logic, doesn’t my code only get the value of userInput after i click the search button?

This is my code: https://codepen.io/CodeMaster1998/pen/QmBjeb?editors=1010