1
错误发生在if语句内部的第38行和第39行之间(根据Chrome JS控制台,我假设这意味着我的错误在第39行)。我不知道我做错了什么,如果任何人都可以帮助我,那真是太棒了。谢谢。如果你想看到的代码之前,我把它弄坏了,这个程序是在http://piratena.me/我有一个JavaScript“意外标识符”错误。谁能帮我?
/*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));
});
});
嗯,这是一个很好的捕获。我来自Python,因为我不必为if语句使用parens,所以我错过了那个。我添加了parens,现在它告诉我:“未捕获的ReferenceError:isAlpha未定义”。我认为Alpha是JS中的一个全局函数。没有? –
没有'isAlpha' javascript'函数'。 – Gabe
恩,当然。我必须使用正则表达式来检查非A-Z字符吗? –