Javascript 有麻烦了!D:

Javascript 有麻烦了!D:,javascript,variables,Javascript,Variables,我正在做一个增量游戏,每个结构都会给你一定数量的饼干。游标给你两块饼干,我要代表给你五块饼干。然而,他们两个都给了两块饼干,我不知道如何改变这一点。这是我的片段。 此外,我如何使其显示我的总cps?CPS是每秒的cookies。我已经包括在内了,但它也不起作用 var cookies = 0; function cookieClick(number){ cookies = cookies + number; document.getElementById("cookies").inne

我正在做一个增量游戏,每个结构都会给你一定数量的饼干。游标给你两块饼干,我要代表给你五块饼干。然而,他们两个都给了两块饼干,我不知道如何改变这一点。这是我的片段。 此外,我如何使其显示我的总cps?CPS是每秒的cookies。我已经包括在内了,但它也不起作用

var cookies = 0;

function cookieClick(number){
  cookies = cookies + number;
  document.getElementById("cookies").innerHTML = cookies;
};

var cps = 0;

function cps(cursors, rep){
  cps = cursors + rep;
  document.getElementById('cps').innerHTML = cps;
};

var cursors = 0;

function buyCursor(number){
  var cursorCost = Math.floor(10 * Math.pow(1.1,cursors));     //works out the cost of this cursor
  if(cookies >= cursorCost){                                   //checks that the player can afford the cursor
    cursors = cursors + 1;                                   //increases number of cursors
    cookies = cookies - cursorCost;                          //removes the cookies spent
    document.getElementById('cursors').innerHTML = cursors;  //updates the number of cursors for the user
    document.getElementById('cookies').innerHTML = cookies;  //updates the number of cookies for the user
  };
  var nextCost = Math.floor(10 * Math.pow(1.1,cursors));       //works out the cost of the next cursor
  document.getElementById('cursorCost').innerHTML = nextCost;  //updates the cursor cost for the user
}; 

var rep = 0;

function buyRep(){
  var repCost = Math.floor(50 * Math.pow(1.2,rep));     //works out the cost of this rep
  if(cookies >= repCost){                                   //checks that the player can afford the rep
    rep = rep + 1;                                   //increases number of rep
    cookies = cookies - repCost;                          //removes the cookies spent
    document.getElementById('rep').innerHTML = rep;  //updates the number of rep for the user
    document.getElementById('cookies').innerHTML = cookies;  //updates the number of cookies for the user
  };
  var nextCost = Math.floor(50 * Math.pow(1.2,rep));       //works out the cost of the next rep
  document.getElementById('repCost').innerHTML = nextCost;  //updates the rep cost for the user
};


window.setInterval(function(){

  cookieClick(cursors);
  cookieClick(rep);

}, 1000);

注意,函数声明不会以分号结尾。在此处检查您的代码是否有错误/警告我删除了所有不必要的分号,但cps函数仍然无法工作。@Elclans不在函数声明后放置分号不是规则。只是一个约定。@AaditMShah:根本不需要放分号,或者一行放5个分号。只是最佳实践,如果不需要分号,为什么要放在那里?我很困惑。您想让我们向您演示如何在
函数cps()
中将游标乘以2并将rep乘以5吗?当然不是。我的意思是,在其他函数中有乘法。