Message Mixer step 6

Hello guys, It seems i’ve been stuck on step 6 in message mixer project. For some reason bash throws and error when even though the line has no code in it. Or am i missing something?
Had asked my friend who just recently started to work as back end and he has no clue what’s going on either.

there is the full code of encryptors.js

// 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'

}

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;

and heres the message-mixer.js

const encryptors = require(’./encryptors.js’)

const caesarCipher = encryptors.caesarCipher;

const symbolCipher = encryptors.symbolCipher;

const reverseCipher = encryptors.reverseCipher;

// User Input / Output Logic

/////////////////////////////////////////////

const encryptionMethod = getEncryptionMethod();

process.stdin.on(‘data’, (userInput) => {

displayEncryptedMessage(encryptionMethod, userInput);

});

/* Helper function for determining which cipher method

the user chose when they ran the program. */

function getEncryptionMethod() {

let encryptionMethod;

const encryptionType = process.argv[2];

if (encryptionType === ‘symbol’) {

encryptionMethod = symbolCipher;

} else if (encryptionType === ‘reverse’) {

encryptionMethod = reverseCipher;

} else if (encryptionType === ‘caesar’) {

let amount = Number(process.argv[3]);

if (Number.isNaN(amount)) {

  process.stdout.write(`Try again with a valid amount argument. \n`)

  process.exit();  

}

encryptionMethod = (str) => caesarCipher(str, amount);

}

else {

process.stdout.write(`Try again with a valid encryption type. \n`)

process.exit();

}

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

return encryptionMethod;

}

/* Helper function for displaying the encrypted message to the user. */

function displayEncryptedMessage(encryptionMethod, userInput) {

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

let output = encryptionMethod(str);

process.stdout.write(\nHere is your encrypted message:\n> ${output}\n)

process.exit();

}

1 Like

Hi Megija,

you can format your code by pressing the </> in the editor while the text is marked. That makes it easier to spot any syntax errors.

A syntax error in a non existing line usually indicates an error of scope. A non closed curly bracket for example. The console does not know where you’d want to close it and therefore locates the error on the line after the last line.

Format your code and take a close look at your function scopes: Are all functions properly closed?

2 Likes