javascript小白,问一个代码问题,卡住了
constcomputerList=["algorithm","alignment","backup","alpha","analog","bandwidth","bin...
const computerList = ["algorithm", "alignment", "backup", "alpha", "analog", "bandwidth", "binary", "boolean", "bug", "cache","capacity", "cell", "client", "code", "database", "debug", "desktop publishing", "encryption", "external storage", "feedback", "firewall", "gigabyte", "hyperlink", "import", "interface", "local area network", "microprocessor", "operating system", "peripheral", "plagiarism"];
const medicalList = ["abnormal", "ache", "ambulance", "biopsy", "blood count", "cancer", "cast", "chemotherapy", "deaf", "discomfort", "fatal", "germ", "genetic", "HIV", "immune system", "infant", "itchy", "light-headed", "malignant", "newborn", "numb", "pain", "paralyzed", "scrubs", "side effects", "therapy", "unconscious", "vein", "ward", "wound"];
const carList = ["Toyota", "Alfa Romeo", "Audi", "Volkswagen", "BMW", "Subaru", "Cadillac", "Chevrolet", "Citroen", "Ferrari", "Ford", "Geely", "GMC", "Honda", "Hyundai", "Infiniti", "Jaguar", "Jeep", "Kia", "Volvo", "Land Rover", "Lexus", "Maserati", "Mazda", "Mercedes-Benz", "Mini", "Peugeot", "Porsche", "Renault", "Rolls Royce"];
//以上是三个数组
var wordLists = select.addEventListener('change', selection);
//这里我把返回的数组给了wordlists了
function selection()
{
var wordList=""; displayWords.innerHTML = ""; input.value = ""; time.innerHTML = "";
result.innerHTML = "";
button.disabled = false;
if(event.value="1")
{ wordList = computerList; }
else if(event.value="2")
{ wordList = medicalList; }
else if(event.value="3")
{ wordList = carList; }
return wordList;//返回数组
}
button.addEventListener('click', startGame);
//按了button运行下面的方法,方法能进去,但是为什么返回的数组进不去呢
function startGame()
{
var randomNumber = Math.round(Math.random()*wordList.length);
button.disabled = true;
displayWords.innerHTML=wordList[randomNumber];
displayWords.style.backgroundColor="lightblue";
displayWords.style.borderWidth="5px";
displayWords.style.borderColor="cornflowerblue";
}
为什么startGame()方法里面用不了wordList这个数组呢? 展开
const medicalList = ["abnormal", "ache", "ambulance", "biopsy", "blood count", "cancer", "cast", "chemotherapy", "deaf", "discomfort", "fatal", "germ", "genetic", "HIV", "immune system", "infant", "itchy", "light-headed", "malignant", "newborn", "numb", "pain", "paralyzed", "scrubs", "side effects", "therapy", "unconscious", "vein", "ward", "wound"];
const carList = ["Toyota", "Alfa Romeo", "Audi", "Volkswagen", "BMW", "Subaru", "Cadillac", "Chevrolet", "Citroen", "Ferrari", "Ford", "Geely", "GMC", "Honda", "Hyundai", "Infiniti", "Jaguar", "Jeep", "Kia", "Volvo", "Land Rover", "Lexus", "Maserati", "Mazda", "Mercedes-Benz", "Mini", "Peugeot", "Porsche", "Renault", "Rolls Royce"];
//以上是三个数组
var wordLists = select.addEventListener('change', selection);
//这里我把返回的数组给了wordlists了
function selection()
{
var wordList=""; displayWords.innerHTML = ""; input.value = ""; time.innerHTML = "";
result.innerHTML = "";
button.disabled = false;
if(event.value="1")
{ wordList = computerList; }
else if(event.value="2")
{ wordList = medicalList; }
else if(event.value="3")
{ wordList = carList; }
return wordList;//返回数组
}
button.addEventListener('click', startGame);
//按了button运行下面的方法,方法能进去,但是为什么返回的数组进不去呢
function startGame()
{
var randomNumber = Math.round(Math.random()*wordList.length);
button.disabled = true;
displayWords.innerHTML=wordList[randomNumber];
displayWords.style.backgroundColor="lightblue";
displayWords.style.borderWidth="5px";
displayWords.style.borderColor="cornflowerblue";
}
为什么startGame()方法里面用不了wordList这个数组呢? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询