How do I use a variable declared in function in another function.
I need the mortgageLimit, mortgageMax, and mortgageStart to be declared when the user clicks the button with the step4 class
$(".step4").click(function() {
   var mortgageLimit = parseInt(document.getElementById("property_value").value) * .80;
   var mortgageMax = parseInt(mortgageLimit * 1000);
   var mortgageStart = mortgageMax * .5;
});
Then I'd like to use mortgageMax and mortgageStart as the min and max of a slider I'm using
var thirdSlider = document.getElementById("estimated_mortgage_value");
noUiSlider.create(thirdSlider, {
    'start': ["220000"],
    'connect': 'lower',
    'format': wNumb({
        decimals: 0,
        thousand: ',',
     }),
     'range': {
         'min': [mortgageStart],
         'max': [mortgageMax]
     },
     'step': 10000
});
I keep on getting a "Uncaught ReferenceError: mortgageStart is not defined" error. I've tried declaring the mortgageStart and mortgageMax as a global variable, but I need the variables declared when the user clicks, so the variables need to be declared within $(".step4").click(function() {