Caesars Cipher - charCodeAt(index) >= always evaluates to true?

Caesars Cipher - charCodeAt(index) >= always evaluates to true?
0

#1

Tell us what’s happening:
When I console.log, it seems that if (str.charCodeAt(index) >= 78) always evaluates to true. Any idea why this is happening?

Your code so far

function rot13(str) { // LBH QVQ VG!
  var newstring ="";
  
  for (var index =0; index < str.length; index++){
  if (str.charCodeAt(index) >= 78);{
    newstring += str.charCodeAt(index) - 13 + ",";
   }
  }
  /*
  if (str.charCodeAt(index) < 78){
    var difference = 0;
    var from13 = 0;
    difference = str.charCodeAt(index) - 65;
    from13 = 13 - difference;
    newstring += 90 - from13 + ",";
    
  }
  */
   console.log(newstring);
  return str;
}

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36.

Link to the challenge:


#2

The semicolon in that statement worries me. I don’t think it should be there.


#3

It actually is not evaluating to true each time. However, you have a semi-colon to the right of the parentheses of the if statement condition:

if (str.charCodeAt(index) >= 78);{ // see to the left of the {

That tells JavaScript to just end the statement. Then what ends up happening is the part between the { } gets executed each time. It is as if there is no if statement. Remove the semi-colon it will act like you were expecting.


#4

Thanks petersim & randelldawson. I didn’t see the semicolon there until you brought it up.