1

エラーは、ifステートメント内の38行目と39行目で発生します(Chrome JS Consoleによると、エラーは39行目にあると思います)。誰かが私を助けてくれるなら、それは素晴らしいことだと思います。ありがとう。私がコードを壊す前にコードを見たい場合は、このアプリはhttp://piratena.me/でライブで実行されています

/*This object is a simple dictionary that matches every letter of the alphabet to a pirate-related string.*/

var altDictionary = {
    a: 'arr', 
    b: 'pegleg', 
    c: 'timber', 
    d: 'monkey', 
    e: 'knife', 
    f: 'powder', 
    g: 'grog', 
    h: 'scuttle', 
    i: 'keel', 
    j: 'cannon', 
    k: 'sparrow', 
    l: 'cutlass', 
    m: 'mast', 
    n: 'plank', 
    o: 'matey', 
    p: 'bag', 
    q: 'doubloon', 
    r: 'rope', 
    s: 'rum', 
    t: 'chip', 
    u: 'lubber', 
    v: 'spit', 
    w: 'patch', 
    x: 'salt', 
    y: 'tack', 
    z: 'tortuga'
}

/*This function loops through the input from the user, replacing each letter in their name with a pirate-related string.*/

var altName = function(name) {
    var result = "";
    for (i=0; i<name.length; i++) {
        var ind=name[i];
        if isAlpha(ind) === true {
            ind = toLowerCase(ind);
            var syl = altDictionary[ind];
            result = result + syl + "-";
        } else {
            alert("Your name can only contain alphabetical letters.");
        }
    }
    result = result.substring(0, result.length - 1)
    return result;
};

/*This block of jQuery inserts the newly created Pirate Name into the output field*/

$(document).ready(function() {
    $('form #click_button').click(function(event) {
        event.preventDefault();
        var name = $('#input_box').val();   
        $('#output p').text(altName(name));
    });
});
4

1 に答える 1

6

私が最初に気付くのはこれです:

if isAlpha(ind) === true 

なぜ括弧がないのですか?

if (isAlpha(ind) === true)

ちなみに、実際の例に移動して、質問で指定したものとは異なるコードが実行されていることを確認することをお勧めします。

于 2012-08-30T23:13:32.747 に答える