小编Bil*_*att的帖子

有没有办法简化这段 JavaScript 代码?

我知道这是一个广泛的问题,但我仍然是新手,不知道要搜索/询问什么。

我有一个 Jeopardy 游戏的 JavaScript 系列。我相信有更好的方法来做到这一点,因为有太多的重复。我正在考虑一些变量、数组和/或在调用函数时传递 ID 但不知道从哪里开始的事情。任何想法,将不胜感激。我不是要求任何人做这项工作,只是给我一些想法和例子来说明要往哪个方向发展。

var score = 0;


//Disable the question button
function disableButton(btnID){
        document.getElementById(btnID.id).disabled = true;
    }

//Show current score
function endQuestion(){
  alert ("Your total score is now " +score);
}

//Toggle Images On
function showImgBtn1(){
  document.getElementById('btn1pic').style.visibility = 'visible';
  setTimeout(askQuestion1,3000);
}
function showImgBtn2(){
  document.getElementById('btn2pic').style.visibility = 'visible';
  setTimeout(askQuestion2,3000);
}
//This keeps going for every question--repeated 9 to 20 times


//Questions
function askQuestion1()
{
  var answer = prompt ("What body system contains the heart, blood, arteries, and …
Run Code Online (Sandbox Code Playgroud)

javascript arrays function simplify

2
推荐指数
1
解决办法
124
查看次数

标签 统计

arrays ×1

function ×1

javascript ×1

simplify ×1