错误发生在 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));
});
});