Hi there I’m struggling with the super-encoder session of Message Mixer because it keeps saying undefined when i run the program. I’ve looked through the forums for the same problem but nothing worked for me, I can’t see where I’m missing something, can anyone help me? this is my code:
const encryptors = require('./encryptors.js');
const caesarCipher = encryptors.caesarCipher;
const symbolCipher = encryptors.symbolCipher;
const reverseCipher = encryptors.reverseCipher;
const encodeMessage = (str) => {
return reverseCipher(symbolCipher(caesarCipher(str,6)));
}
const decodeMessage = (str) => {
return caesarCipher(symbolCipher(reverseCipher(str)), -6);
}
also here’s the link to the exercise: https://www.codecademy.com/paths/back-end-engineer-career-path/tracks/becp-javascript-syntax-part-iii/modules/becp-learn-javascript-syntax-node-modules/projects/message-mixer-node
What’s the exact error mesage, and what’s the contents of encryptors.js?
When I run the program the function returns ‘Undefined’
The contents:
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(' ');
};
Nevermind, just found my problem, thank you!!! 
What was the problem? I’m having the same “Undefined” issue and I have no idea what to look for.
1 Like
me too, same prob here and nowhere to look for an answer…