Home > Software design >  I need function that calculates amount of games required to reach certain rating with defined winrat
I need function that calculates amount of games required to reach certain rating with defined winrat

Time:12-07

function ChangePts(pts) {
  this.pts = pts;
  
  this.win = function() {
    console.log(this.pts   30)
    return this.pts  = 30
  }

  this.lose = function() {
    console.log(this.pts - 30)
    return this.pts -= 30;
  }

};
           

I made it to calculate how many games you need to lose, to get certain ratingw with while loop. This implies that win% is 0%, how do I calculate amount of games if we declare starting pts for example 5000, how many games it takes to get to 1000 pts if your winrate is 27% P.S.: For this case I need only negative amount of win%.

CodePudding user response:

I don't know if this is what you are looking for. I've created a function which will return a count number.

const func = (points, winRate)=>{
    // You need to enter the total points and the win rate to the function.
   const loseRate = (100-winRate) /100;
    // Above calculating the lose rate according to entered winRate
    let counter =0;

    while(points > 1000){
      // decreasing the points using loseRate till it becomes 1000
      points = points - points * loseRate;
      //increasing the counter value, this will increase each time while loop runs.
       counter   
     }
      //returning the final counter
     return counter;
    }

For example:const howManyTimes = fun (5000,20) console.log(howManyTimes) The answer will be 1 because if winningRate is 20 losing rate will be 80 5000-5000*80/100 = 1000 it reaches 1000 points in one go.

If you meant something else, I am sorry. That is what I understood. I could edit the answer, if you could be more specific though :D

CodePudding user response:

You can just calculate it like this (variables should be explanation enough). There is no real coding necessary for it, just math calculations

const winRate = 0.27
const loseRate = 1-winRate
const pointsWin = 30
const pointsLose = 30
const startingPoints = 5000
const targetPoints = 1000

const pointsGainedOnAverage = pointsWin*winRate - pointsLose*loseRate
const pointsDistance = targetPoints - startingPoints
const games = pointsDistance / pointsGainedOnAverage
console.log('games', games)

CodePudding user response:

Now you can browse privately, and other people who use this device won’t see your activity. However, downloads, bookmarks and reading list items will be saved.

  • Related