0

I want to change the inputLanguage that I input into the value 'en'. When I tried this method, the error that they return is english is not defined.

Here is my alchemy.js

    module.exports = function(Alchemy) {
 Alchemy.language = function(inText, inputLanguage, outputLanguage, cb) {
    console.log('Input text is ' + inText);
    console.log('Input language is ' + inputLanguage);
    console.log('Output language is ' + outputLanguage);
    getCode(inputLanguage, outputLanguage, cb);
  }

  Alchemy.remoteMethod(
    'language', {
      http: {
        path: '/language',
        verb: 'get'
      },
      accepts: [{
        arg: 'inText',
        type: 'string',
        required: true
      }, {
        arg: 'inputLanguage',
        type: 'string',
        required: true
      }, {
        arg: 'outputLanguage',
        type: 'string',
        required: true
      }],
      returns: {
        arg: 'results',
        type: 'string'
      }
    }
  );
  function getCode(inputLanguage, outputLanguage, cb) {
      if (inputLanguage = english) {
          inLang = en;
          console.log('Input language is ' + inlang)
      }
  }
};
sxxxxxxx
  • 565
  • 2
  • 6
  • 17

2 Answers2

1

problems are in blockif (inputLanguage = english)

First, english is undefined variable, so define it, or if you want change it to string, add quotation marks.

Second issue is = sign, single = is assigment, if you want to compare variable, then you need to use == or ===

user902383
  • 8,420
  • 8
  • 43
  • 63
0

You are confusing how if, variables and strings work. There is neither a variable called english, nor en -- and = assigns, == or === are checking for equality => see here.

Try it with below:

if (inputLanguage === 'english') {
      inLang = 'en';
      console.log('Input language is ' + inlang)
}

In JS, strings are enclosed by " or '

Community
  • 1
  • 1
baao
  • 71,625
  • 17
  • 143
  • 203