I did like whatthe answer above said but although, but it didn't worked withwork for me at first because I was declaring these variables inside JQuery
jQuery $( document ).ready().
soSo make sure you declare your variables inside the <script> tag not somewhere else.