I need help with Message Mixer Project step 6

There is seriously no walkthrough project video for message mixer project!!
I need help with message mixer project step six which I’m stuck on.
My code:

// Declare and export the functions here.
const caesarCipher = (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;
};

const symbolCipher = (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;
}

const reverseCipher = (sentence) => {
  let words = sentence.split(' ');
  for (let i = 0; i < words.length; i++) {
    words[i] = words[i].split('').reverse().join('');
  }
   return words.join(' ');
};

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

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

bash:

$ node message-mixer.js caesar 4
Enter the message you would like to encrypt...
> cnawp fkx!
/home/ccuser/workspace/modules-message-mixer/message-mixer.js:30
    encryptionMethod = (str) => caesarCipher(str, amount);
                                ^

ReferenceError: caesarCipher is not defined
    at encryptionMethod (/home/ccuser/workspace/modules-message-mixer/message-mixer.js:30:33)
    at displayEncryptedMessage (/home/ccuser/workspace/modules-message-mixer/message-mixer.js:44:16)
    at ReadStream.process.stdin.on (/home/ccuser/workspace/modules-message-mixer/message-mixer.js:11:3)
    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)

please help

I assume these 4 lines for importing stuff are at the beginning of the other file:   message-mixer.js

I tried to fix it it’s still not working can you please help further

Try exporting like this:

 module.exports =  {caesarCipher, symbolCipher, reverseCipher}

and importing like this

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

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.