I am creating a cipher that takes a string and changes each letter to move forward 3 spaces. For instance "Hello!" would turn into "Khoor!", but I have hit a snag. When people type in something that isn't a letter, like a "!" or a space in between letters, I want to be able to just return that value. So a "!" would stay a "!" and a space would stay a space. I want to create an if statement inside of a loop to accomplish this, but how do I differentiate between letters and non-letters?
Attached is my loop, and I want to be able to put in an if statement so it would read "if input is non-letter, then return input. If input is a letter then move forward 3 spaces."
var alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
var string = "Hello World!"
var stringArr = string.split("")
var codedLet = [];
for (var i = 0; i < string.length; i++) {
var input = stringArr[i].toLowerCase()
var codedNum = alphabet.indexOf(input) + 3
codedLet[i] = alphabet[codedNum]
}