错误发生在第38行和第39行之间,在if语句中(根据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));
});
});
答案 0 :(得分:6)
我注意到的第一件事是:
if isAlpha(ind) === true
为什么没有括号?
if (isAlpha(ind) === true)
顺便说一下,建议我们转到您的实例,以了解您运行的代码与您在问题中提供的代码不同,这没有任何帮助。