text: Q:
  
  Trying to set dynamic JS variables in a function globally
  
  I'm trying to set local storage values using dynamic variables from within a function what will be looped through.  Basically i'm just trying to do this (which works but isn't dynamic):
   localStorage.lvlZeroValue = localStorage.lvlZeroMaxValue;
  
  using this: 
  counterMarkers[numberID] = maxMarkers[numberID];
  
  but it's not affecting 'localStorage.lvlZeroValue' at a global level
  $('#spellCountTackMax').click(function() {
  
      var counterMarkers = [
          localStorage.lvlZeroValue,
          localStorage.lvlOneValue,
          localStorage.lvlTwoValue,
          localStorage.lvlThreeValue,
          localStorage.lvlFourValue,
          localStorage.lvlFiveValue,
          localStorage.lvlSixValue,
          localStorage.lvlSevenValue,
          localStorage.lvlEightValue,
          localStorage.lvlNineValue
      ];
  
      var maxMarkers = [
          localStorage.lvlZeroMaxValue,
          localStorage.lvlOneMaxValue,
          localStorage.lvlTwoMaxValue,
          localStorage.lvlThreeMaxValue,
          localStorage.lvlFourMaxValue,
          localStorage.lvlFiveMaxValue,
          localStorage.lvlSixMaxValue,
          localStorage.lvlSevenMaxValue,
          localStorage.lvlEightMaxValue,
          localStorage.lvlNineMaxValue
      ];
  
          jQuery.fn.onTackSet = function(numberID){
  
              return this.each(function(){
  
                  if(maxMarkers[numberID] == "" || maxMarkers[numberID] == null || maxMarkers[numberID] == 0 ) {
  
                      alert("not else ran");
                      $(this).attr('value', "0");
                      $('#spin' + numberID).attr('value', "0");
                      counterMarkers[numberID] = "0";
                      maxMarkers[numberID] = "0";
  
                  } else {
                      alert("else ran");
                      $(this).attr('value', maxMarkers[numberID]);
                      $(this).attr('max', maxMarkers[numberID]);
                      // localStorage.lvlZeroValue = localStorage.lvlZeroMaxValue;
                      alert(counterMarkers[numberID]);
                      alert(maxMarkers[numberID]);
  
                      // this works but isn't dynamic
                      localStorage.lvlZeroValue = localStorage.lvlZeroMaxValue;
  
                      // my attempt at making it dynamic doesn't seem to work globally
                      counterMarkers[numberID] = maxMarkers[numberID];
  
                  }
              });
          };
  
          $("#spin0").onTackSet(0);
  
  So i'm pretty sure my issue is scope, yet i can't seem to get it right.  Please, help.  Thanks!
  
  A:
  
  Do you need to keep the keys for your storage values the way you have them? If you could change them from lvlZeroValue to lvl0Value you could use the approach below:
      jQuery.fn.onTackSet = function(numberID){
  
              return this.each(function(){
  
                  if(localStorage['lvl'+numberID+'MaxValue'] == "" || localStorage['lvl'+numberID+'MaxValue'] == null || localStorage['lvl'+numberID+'MaxValue'] == 0 ) {
  
                      alert("not else ran");
                      $(this).attr('value', "0");
                      $('#spin' + numberID).attr('value', "0");
                      localStorage['lvl'+numberID+'Value'] = "0";
                      localStorage['lvl'+numberID+'MaxValue'] = "0";
  
                  } else {
                      alert("else ran");
                      $(this).attr('value', localStorage['lvl'+numberID+'MaxValue']);
                      $(this).attr('max', localStorage['lvl'+numberID+'MaxValue']);
  
                      localStorage['lvl'+numberID+'Value'] = localStorage['lvl'+numberID+'MaxValue'];
  
                  }
              });
          };
  
  If you need to keep the keys you have now you still could adapt the above approach to your needs by building your arrays different:
  var markers = [
          'lvlZeroValue',
          'lvlOneValue',
          'lvlTwoValue',
          'lvlThreeValue',
          'lvlFourValue',
          'lvlFiveValue',
          'lvlSixValue',
          'lvlSevenValue',
          'lvlEightValue',
          'lvlNineValue'
      ];
  var maxMarkers = [
          'lvlZeroMaxValue',
          'lvlOneMaxValue',
          'lvlTwoMaxValue',
          'lvlThreeMaxValue',
          'lvlFourMaxValue',
          'lvlFiveMaxValue',
          'lvlSixMaxValue',
          'lvlSevenMaxValue',
          'lvlEightMaxValue',
          'lvlNineMaxValue'
      ];
  
  and use them like this:
  localStorage[markers[numberID]] = localStorage[maxMarkers[numberID]];
  
  Here is a fiddle to see how it works.
  
  