Caesars Cipher: Correct Values are shown in console.log but still i cannot pass
See original GitHub issueChallenge Caesars Cipher has an issue.
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
.
Please describe how to reproduce this issue, and include links to screenshots if possible.
My code:
function rot13(str) { // LBH QVQ VG!
var res="";
for(var i=0;i<=str.length;i++){
if((str.charCodeAt(i)==32)||(str.charCodeAt(i)<=64))
delta=str.charCodeAt(i);
else if((str.charCodeAt(i))>77)
delta=str.charCodeAt(i)-13;
else
delta=str.charCodeAt(i)+13;
res+=String.fromCharCode(delta);
}
return res;
}
// Change the inputs below to test
//rot13("SERR");
console.log(rot13("SERR PBQR PNZC"));
console.log(rot13("SERR CVMMN!"));
console.log(rot13("SERR YBIR?"));
console.log(rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK."));
I made a test in my browser, and it delivers all the correct values, but still i don’t pass.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Caesars Cipher / Shift Caesar code is not working
The previous answer is correct (the replace function returns a string, doesn't perform an update on the original input).
Read more >Discuss Caesar Cipher Helper - Codewars
I solved the Kata and could verify that the output of my function (wrong code) is shown as "expected" and the expected value...
Read more >freecodecamp: Caesars Cipher - gists · GitHub
Write a function which takes a ROT13 encoded string as input and returns a decoded string. All letters will be uppercase. Do not...
Read more >Destructuring assignment - The Modern JavaScript Tutorial
Destructuring assignment is a special syntax that allows us to “unpack” arrays or objects into a bunch of variables, as sometimes that's more ......
Read more >Shift cipher (article) - Khan Academy
The Caesar Cipher is a type of shift cipher. Shift Ciphers work by using the modulo operator to encrypt and decrypt messages. The...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
for(var i=0;i<=str.length;i++){
should bei < str.length
Your result might look correct, but they actually have a \x0 at the end.
What @rawgni said.
@hanhoah please ensure you have asked for help, or that someone could confirm the issue in the
Help
chatrooms before posting an issue on github. You can access the correct chat room for your challenge by clicking on theHelp
button in the side panel.Closing as coding error.