Https://www.codecademy.com/courses/introduction-to-javascript/projects/message-mixer-node

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

https://www.codecademy.com/courses/introduction-to-javascript/projects/message-mixer-node

Hi, everyone… I have this problem here, and I don´t understand what is the message error, I need help please…

When I use encode, all looks fine, but when I use decode I have this error…

/home/ccuser/workspace/modules-message-mixer/encryptors.js:4
return caesarCipher(str, amount + 26);
^

ReferenceError: caesarCipher is not defined
at module.exports.caesarCipher (/home/ccuser/workspace/modules-message-mixer/encryptors.js:4:12)
at decodeMessage (/home/ccuser/workspace/modules-message-mixer/super-encoder.js:12:10)
at ReadStream.handleInput (/home/ccuser/workspace/modules-message-mixer/super-encoder.js:25:14)
at emitOne (events.js:96:13)
at ReadStream.emit (events.js:191:7)
at readableAddChunk (_stream_readable.js:178:18)
at ReadStream.Readable.push (_stream_readable.js:136:10)
at TTY.onread (net.js:561:20)

this the super-encoder file

// Import the encryptors functions here.

const {caesarCipher, symbolCipher, reverseCipher} = require("./encryptors.js");

const encodeMessage = (str) => {

  // Use the encryptor functions here.

  return reverseCipher(symbolCipher(caesarCipher(str,6)));

  

}

const decodeMessage = (str) => {

  // Use the encryptor functions here.

  return caesarCipher(symbolCipher(reverseCipher(str)),-6);

  

}

// User input / output.

const handleInput = (userInput) => {

  const str = userInput.toString().trim();

  let output;

  if (process.argv[2] === 'encode') {

    output = encodeMessage(str);

  } 

  if (process.argv[2] === 'decode') {

    output = decodeMessage(str);

  } 

  

  process.stdout.write(output + '\n');

  process.exit();

}

// Run the program.

process.stdout.write('Enter the message you would like to encrypt...\n> ');

process.stdin.on('data', handleInput);

this is the encryptors file

// Declare and export the functions here.

module.exports.caesarCipher = function(str, amount = 0)  {

  if (amount < 0) {

    return caesarCipher(str, amount + 26);

  }

  let output = '';

  for (let i = 0; i < str.length; i++) {

    let char = str[i];

    if (char.match(/[a-z]/i)) {

      let code = str.charCodeAt(i);

      if (code >= 65 && code <= 90) {

        char = String.fromCharCode(((code - 65 + amount) % 26) + 65);

      } else if (code >= 97 && code <= 122) {

        char = String.fromCharCode(((code - 97 + amount) % 26) + 97);

      }

    }

    output += char;

  }

  return output;

};

module.exports.symbolCipher = function(str)  {

  const symbols = {

    'i': '!',

    '!': 'i',

    'l': '1',

    '1': 'l',

    's': '$',

    '$': 's',

    'o': '0',

    '0': 'o',

    'a': '@',

    '@': 'a',

    'e': '3',

    '3': 'e',

    'b': '6',

    '6': 'b'

  }

  let output = '';

  for (let i = 0; i < str.length; i++) {

    let char = str.toLowerCase()[i];

    if (symbols[char]) {

      output += symbols[char]

    } else {

      output += char;

    }

  }

  return output;

}

module.exports.reverseCipher = function(sentence)  {

  let words = sentence.split(' ');

  for (let i = 0; i < words.length; i++) {

    words[i] = words[i].split('').reverse().join('');

  }

   return words.join(' ');

};

Hi! I encountered the same error today and found the root cause!
Look:

In encryptors.js file there is another callout of caesarCipher() function in case if amount is lesser than 0 (that would be the case if you have used the proposed hint solution). That function callout become incorrect when it is being called as a module from another project file. So to make it work you’d need to either also add export mark ti the function callout, i.e.

module.exports.caesarCipher = function(str, amount = 0)  {

  if (amount < 0) {

    return module.exports.caesarCipher(str, amount + 26);

  }

or export function like this:

module.exports.caesarCipher = caesarCipher;

Hope it helps!

Thank you very much…
You’re amazing…
I appreciate a lot your help…
And yes , I had to try this program with the solution because I think is a high level exersice, so, I hope to can understand the funcionality and I hope to do things like that soon… no yet… :frowning: