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.

1 Like

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

1 Like