Strings and Switches

So, I've been trying for hours to get this to work, and I seem to not be getting anywhere. I've had people that are decent in JS tell me that this should work, but it doesn't.

So this is an example code of what I'm trying to do:

Code:
var  sampleVar = toNumber(parameters['Sample'], 0); 

Game.blah.blah = function() {
  
  switch (sampleVar) {
    case 0:
      return (value);
    break;
    
    case 1:
      return (vale);
    break;
  }
};

So when I do this, its not working as I think it should have worked. sampleVar doesn't seem to be putting out 0 nor 1.

Any ideas?

Cheers!
Where does toNumber come from?
You can either use Number(parameters['Sample']) or parseInt(parameters['Sample']).

Also what do you wanna do with return (value)?
As stated above, toNumber by itself is not a function in JavaScript. Additionally, what is "parameters"? Based on the name I can make an assumption, but assumptions are evil. Please show us more of what you're actually working with so we can better understand what might be going wrong.

Also, are there any errors that are being thrown, or anything to give us more information about specifically what's not working? If you're running this in a game through MV, press F12 to bring up the developer console and get more detailed error information.
Well, the code you provided has quite a bit of errors.

toNumber is not the function you should be using. Use Number instead, or parseInt if you want an integer number.

You did not define parameters in the code. Also, not sure what you're trying to do with the ", 0" in that line.

Game.blah.blah is not going to work. None of those things are defined.

Inside that function, value is not defined, so your function is going to be returning undefined (if it even works).

I can't and don't want to make assumptions of what you're trying to do, so more information is necessary to understand the problem better. Providing the full plugin would be better instead of a small part of it.
toNumber seems to be working in several plugins ive seen, so I thought it would work. But I guess I'll post all my code then:

Code:
(function() {

  var parameters = PluginManager.parameters('BM_Difficulty');

  // Difficulty Setting
  // 0 = easy, 1 = normal, 2 = hard.
  // You can add difficulties, just make sure you change what needs to be
  // changed!
  var diffSetting = toNumber(parameters['Difficulty Setting'], 0);

  // Easy Multipliers
  var easyParam = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5];
  var easyExp = 2;
  var easyGold = 2;

  // Normal Multipliers
  var noramlParam = [1, 1, 1, 1, 1, 1, 1, 1];
  var normalExp = 1;
  var normalGold = 3;

  // Hard Multipliers
  var hardParam = [20, 20, 20, 20, 20, 20, 20, 20];
  var hardExp = 0.75;
  var hardGold = 4;

// End 'noob friendly' Customization
  var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  Game_Interpreter.prototype.pluginCommand = function(command, args) {
      _Game_Interpreter_pluginCommand.call(this, command, args);
      if (command === 'DifficultySetting'){

        switch (args[0]) {
          case 'easy':
             return diffSetting = 0;
          break;

          case 'normal':
             return diffSetting = 1;
          break;

          case 'hard':
             return diffSetting = 2;
          break;

      }// end switch
    }// end if statement
  }; // end pluginCommand


  // Gold calculations
  Game_Enemy.prototype.gold = function() {
    switch (diffSetting) {
        case 0:
          return this.enemy().gold * easyGold;
        break;

        case 1:
          return this.enemy().gold * normalGold;
        break;

        case 2:
          return this.enemy().gold * hardGold;
        break;

        default:
          return this.enemy().gold * easyGold;
        break;

    }

  };





})();

EDIT:
Nevermind I figured it out:

Code:
  function toNumber(str, def) {
      return isNaN(str) ? def : +(str || def);
  }

I though toNumber was a builtin function, so i just defined it myself.

Original thread: https://forums.rpgmakerweb.com/threads/strings-and-switches.80719/