Message Mixer Super-encoder undefined

Hi, I’m continually getting ‘undefined’ when I try to run ‘node super-encoder.js encode’ or ‘decode’ in the last step of Message Mixer. I have really simplified my code using the suggested hints to try and isolate the error, have tried restarting the project from the top, but I have the same sticking point each time. It works fine using the node commands from message-mixer.js, so I don’t think it’s a problem with my import or export methods or with encryptors.js. Hoping someone can help as I’m sure I’m missing something blindingly obvious :slight_smile: :sweat_smile: My code from super-encoder.js:

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

const encodeMessage = (str) => {
  // Use the encryptor functions here.
  return 
  symbolCipher(reverseCipher(caesarCipher(str, 12)));
}

const decodeMessage = (str) => {
  // Use the encryptor functions here.
  return
  caesarCipher(reverseCipher(symbolCipher(str)),-12);
}

// 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);

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

Hi @anyatemple0816931093, welcome to the forum!

You moved value to be returned to the next line

That is as if you wrote

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

Just the first line is executed, which means nothing is returned.

2 Likes

Thank you mirja! I can’t believe I didn’t try that. It works now. Much appreciated :slight_smile:

2 Likes

Hi!! I am having some issues with this too. no matter what I do it says that symbolCipher is not a fucntion so the program only works without it. Have you an idea as to why?

There are plenty of possible causes for that. You have to provide more information if anybody should be able to help.
The best would be to open a new topic and post your code. Please make sute it’s properly formatted:
How to format code in posts

I have the same issue. it says “reverseCipher is not a function”. Please help.
Thank you

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

const encodeMessage = (str) => {
  return reverseCipher(symbolCipher(caesarCipher(str, 6)));
}

const decodeMessage = (str) => {
  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);

Hi Vlad,
how do you export the functions from the encryptors file? Can you post the code as well?

1 Like

Hello
Export from encryptors.js:

module.exports.caesarCipher = caesarCipher;
module.exports.symbolCipher = symbolCipher;
module.exports.reverseCipher - reverseCipher;

And I can see the problem here :grinning: Thank you Mirja! May you share how did you know that the problem is in export?

1 Like

You import the functions from encryptors.js. So either there is a problem in the file that imports the function reverseCipher – like a misspelling – or the problem is within the file that exports the function. I could not see a misspelling, so I assumed the latter.

1 Like

I was getting ReferenceError: caesarCipher is not defined when doing the last steps of the super-encoder.js file.

The problem was actually in the encryptors.js file. While I had turned the function into module.exports I also needed to update line 5 with module.exports when the caesarCipher loops back on itself with a negative value.

See below for reference: