javascript - 我有一个 JavaScript "Unexpected Identifier"错误。谁能帮我?

标签 javascript json function

<分区>

错误发生在 if 语句内的第 38 行和第 39 行之间(根据 Chrome JS 控制台。我认为这意味着我的错误在第 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));
    });
});

最佳答案

我首先注意到的是:

if isAlpha(ind) === true 

为什么没有括号?

if (isAlpha(ind) === true)

顺便说一句,建议我们查看您的实际示例以发现您运行的代码与您在问题中提供的代码不同,这无济于事。

关于javascript - 我有一个 JavaScript "Unexpected Identifier"错误。谁能帮我?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12206878/

相关文章:

javascript - 我想加载谷歌地图信息窗口中文件夹中的所有图像

javascript - console.log 未显示正确的值

java - Spring-MVC & Android : Server gets a empty JSON string from android

javascript - 从文本区域获取 JSON 数据

function - 传播执行状态

css - CSS 函数 -webkit-named-image() 的规范是什么?

javascript - 通过添加事件监听器禁用上下文菜单(右键单击时看到的选项)不起作用

javascript - 如何使用 CSS/Reactjs 禁用 youtube 视频上的观看和分享按钮

c# - 使用 SignalR 发送 JSON

c++ - 函数调用中的 WriteConsole 访问冲突但不是来自 main()