Caesars Cipher Error

Hello guys,

I already passed this Challenge, but I’m wondering why my first solution shows me an error message, maybe you can enlight me. :slight_smile: What’s wrong with it?

function rot13(str) { // LBH QVQ VG!

function allLetter(inputtxt)
{
var letters = /^[A-Za-z]+$/;
if(inputtxt.value.match(letters))
return true;
else
return false;
}

var newString=[];
for(i=0;i<str.length;i++){
if(allLetter(str[i]) !== true){
newString.push(str.charAt(i));
} else if(str.charCodeAt(i) > 77){
newString.push(String.fromCharCode(str.charCodeAt(i)-13));
} else {
newString.push(String.fromCharCode(str.charCodeAt(i)+13));
}
}
return newString.join("");
}

// Change the inputs below to test
rot13(“SERR PBQR PNZC”);

// Error message is the following: TypeError: Cannot read property ‘match’ of undefined

This line is the culprit. Specifically the value part. inputtxt is already a string, and you could’ve just used inputtxt.match(letters).


I don’t know if you used this in your working solution, but you could simplify allLetter to this:

function allLetter(inputtxt) {
  var letters = /^[A-Za-z]+$/;
  return letters.test(inputtxt);
}
1 Like

thx dude, that worked