Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
Google Apps Script error mistaking variable for a function

I am making an Elo rating leaderboard system in Google Sheets using Apps Script and while executing the following function which calculates the Elo changes I get the error "TypeError: kleft is not a function" I do not understand why my variable "kleft" is being mistaken for a function or where I am going wrong since I've written a similar code multiple times before without any issues.

//function to calculate Elo change
function elorat(leftscore,rightscore){ //leftscore and rightscore are the actual points scored by the two players in the match
  var sheet = SpreadsheetApp.getActive();
  var mtd = sheet.getSheetByName('MTD');
  var leftelo = mtd.getRange("K4").getValue(); //elo of player 1 before the game
  var rightelo = mtd.getRange("N4").getValue(); //elo of player 2 before the game
  var expectleft = 1/(1 + Math.pow(10,(rightelo-leftelo)/1000)); //expected points scored by player1 
  var expectright = 1/(1 + Math.pow(10,(leftelo-rightelo)/1000)); //expected points scored by player2
  var kleft = 0; //declaring the k-factor to be used in calculations
  var kright = 0;
  if(1000<leftelo<9000){
    var kleft = Math.round((-0.00001125*(leftelo-1000)*(leftelo-9000))+20); //adjusting k-factor of player1 based on current elo
  }
  else{
    var kleft = 20; //boundary case
  }
  if(1000<rightelo<9000){
    var kright = Math.round((-0.00001125*(rightelo-1000)*(rightelo-9000))+20);
  }
  else{
    var kright = 20;
  }
  var leftchange = Math.round(kleft(leftscore-expectleft)); //amount of change in elo post match for player1
  var rightchange = Math.round(kright(rightscore-expectright)); //amount of change in elo post match for player2
  mtd.getRange("K5").setValue(leftchange); //setting values onto the sheet
  mtd.getRange("N5").setValue(rightchange); 
  mtd.getRange("K6").setValue(leftelo+leftchange); 
  mtd.getRange("N6").setValue(rightelo+rightchange);  
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There are a couple of issues.

Issue 1:

First of all, this expression if(1000<leftelo<9000) evaluates always to true.

You can test it yourself if you console.log(1000<5<9000) you will still get true.

Replace it with:

if(leftelo > 1000 && leftelo < 9000)

and the same for rightelo

Issue 2:

Both kleft and kright are normal variables but you use them indeed as functions and this is why the compiler gives that error.

In almost all of the programming languages this expression kleft(leftscore-expectleft) means that you have a function with the name kleft and you are trying to pass a value that is the result of leftscore-expectleft.

What you want instead is to multiply kleft with (leftscore-expectleft):

kleft * (leftscore-expectleft)
kright * (rightscore-expectright)

Finally, I am not sure where you are calling the elorat function. If this is all your code, then again, this won't work because this function is expecting two arguments. But since you didn't get an error for that, I assume there is some code that is not shared here.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda