Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Javascript question

Name: Anonymous 2009-02-16 15:21

Hi /prog/, due to some stupid thread on /g/, I just wrote a little Javascript thing to do ROT translations for any given degree (typically 13).  It works fine, but I feel like the way I deal with ASCII values that go "out of range" is inelegant.  Any suggestions?

Also, I've never posted here before, so I apologize if the code formatting is fucked up.


function translate(orig, degree) {
    var output = "";
    var x, y;
    for(var i = 0; i < orig.length; i++) {
        x = parseInt(orig.charCodeAt(i));
        //alert(x);
        if (65 <= x && x <= 90) {
            y = parseInt(orig.charCodeAt(i) + parseInt(degree));
            if (y > 90) {
                y -= 26;
            }
            output += String.fromCharCode(y);
        } else if (97 <= x && x <= 122) {
            y = parseInt(orig.charCodeAt(i) + parseInt(degree));
            if (y > 122) {
                y -= 26;
            }
            output += String.fromCharCode(y);
        } else {
            output += orig.charAt(i)
        }
    }
    return output;
}

Name: Anonymous 2009-02-16 15:42

>>7
Incidentally, that doesn't quite work.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List