Tell us what’s happening:
Describe your issue in detail here.
This is not the first time code has worked in VSCode, in local server, and using console.log in fCC’s own code window… but when I change console.log() to return, the test doesn’t pass.
What gives…?
**Your code so far**
function rot13(str) {
const theCode = [];
var az;
for (let i = 0; i <= str.length; i++) {
az = str.charCodeAt(i);
if (az < 65) {
theCode.push(String.fromCharCode(az));
} else {
az += 13;
if (az > 90) {
az = (az - 90) + 64;
theCode.push(String.fromCharCode(az));
} else {
theCode.push(String.fromCharCode(az));
}
}
}
console.log(theCode.join(''));
}
rot13("SERR PBQR PNZC");
rot13("SERR CVMMN!");
rot13("SERR YBIR?");
rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.");
**Your browser information:**
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36
You got the output to the terminal. That was not the purpose of the challenge. I’m not saying it doesn’t output the correct string, I’m saying that it doesn’t meet the requirements:
Write a function which takes a ROT13encoded string as input and returns a decoded string.
Reread that, paying special attention to the last 4 words. Then please add the test code I suggested.
I’m saying that the challenge requires you to return the correct data to fulfill the requirements. It is not doing that. You are suggesting a way to fix that. Why not try it out?
I was referring to the code you provided. I’m not looking for an Ikea, “build the code that MiniClaw is thinking about” project.
But yes, with that return statement it still fails.
I was trying to give you some debugging techniques. Why is your string not passing even though it looks the same? If I apply debugging techniques a little further, I would add:
console.log(theCode)
on the line before your return statement. That make it more clear what the issue is.
It’s not all sorted. I would want to figure out why it is not working correctly. It is a bad habit for a developer to get into saying, “I have no idea why it broken, but this bandaid seems to make it work.”
I suspect that you may want to have a close look at this line:
True. Brain f.rt thatI didn’t see until I viewed the array as an unjoined one… and then clarity. There was a little u0000 null character at the end of every sentence…
Good thing I don’t have hair to pull out