Tell us what’s happening:
Hi everyone. I have a solution which seems to produce the correct outputs, but they are not being accepted as valid answers. I’ve tried to figure out why this could be, but I can’t come up with anything. Does anyone have any thoughts?
Thanks in advance.
Your code so far
var cipherSet = ['N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M'];
var outputArray = [];
var outputString;
function isLetter(str)
{
return (str.length === 1 && str.match(/^[A-Z]*$/));
}
function rot13(str)
{// for non-alphabetic characters; do not transform them. pass them along to outputArray
// for every character in the input string, locate that character in alphabetSet
// use the index value into alphabetSet on cipherSet to find the encoded value.
// after the encoded value is found, put it into outputAray
for(var i = 0; i < str.length; i++)
{// for every character in the string ...
if(isLetter(str[i]))
{// if the character IS a letter...
outputArray.push(cipherSet[alphabetSet.indexOf(str[i])]);// index where the letter in found
}
else
{// if the character is NOT a letter ...
outputArray.push(str[i]);
}
}
outputString = outputArray.toString().replace(/,/g, '');
return outputString;
}
// Change the inputs below to test
rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.
Link to the challenge:
https://www.freecodecamp.org/challenges/caesars-cipher