N_ALPHA = 6;
N_CHOICES = 4;
ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var alphabet = ALPHABET.substring(0, N_ALPHA);
var indexForm=new Array();
function guessStrToArr(inStr)
{
{
for (i=0;i<N_CHOICES;i++)
{
indexForm[i]=alphabet.indexOf(inStr.charAt(i).toUpperCase());
}
}
return indexForm;
}
function numBulls(guess, goal)
{
guess=new Array (guessStrToArr(prompt('enter your guess1')));
alert(guess);
goal=new Array(guessStrToArr(prompt('enter your guess2')));
var checkArray = new Array (guess.concat(goal);
alert(checkArray);
var count=0;
for (i=0;i<N_CHOICES;i++)
{
if (guess[i]===goal[i])
{
count++
}
}
return count;
}
numBulls();
当我运行上面的代码时,它返回相同的数组,每次我在提示框输入不同的代码。我不知道为什么,你能帮帮我吗?非常感谢。