freeCodeCamp: Caesars Cipher: My code pass all the tests but doesn't validate on FCC
Challenge Caesars Cipher has an issue.
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36.
The code pass all the tests but doesn’t validate on FCC editor. Why that?
My code:
let engine = (v) => {
let low = 'A'.charCodeAt();
let high = 'Z'.charCodeAt();
if (!!v.match(/[a-z]/i)) {
if (v.charCodeAt() - 13 < low) {
let code = (high - (low - (v.charCodeAt() - 13 + 1)));
return String.fromCharCode(code);
}
else {
return String.fromCharCode(v.charCodeAt() - 13);
}
}
else {
return v;
}
};
function rot13(str) { // LBH QVQ VG!
return '"' + str
.split('')
.map(engine)
.join('') + '"';
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
rot13("SERR CVMMN!");
rot13("SERR YBIR?");
rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.");
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 23 (18 by maintainers)
Yeah @eakl I got that too… I share your frustration. Anyhow to contributors please update the messages to not have the quotes.
as in:
for all the tests.
Nice catch @BKinahan , but that has raised two issues:
Sorry guys, but the code is incorrect. Running the code above with two minor changes allows it to pass all tests.
The original code returns a string containing an extra pair of double quotes, eg
'"FREE PIZZA!"'instead of'FREE PIZZA!', and deleting the pair of double quote concatenations in the return statement fixes that problem.There does seem to be some conflict with the inner workings of the editor when using the variable name
engine, but this doesn’t stop the tests from passing successfully.