Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

84
Views
I am having trouble with the streak and calculating the win percentage in my JavaScript game

I am trying to implement a stats table into my game. Currently it's very buggy: the streak works when the if statement is true, but if I get the words correct once, the streak goes up and if I get the words correct again the streak goes up. When the statement is false the streak goes back to 0 (which I want to happen).

The problem arises when I get the words correct again, the streak does not increment anymore.

Also the win percentage sometimes works and sometimes the calculations are incorrect. Have I set the function up incorrectly?

if (guessedLetters.length == figureGuessWordsLength) {
  LSdataWordle.CurrrentStreak++;
  if (LSdataWordle.CurrrentStreak >= LSdataWordle.MaxStreak) {
    LSdataWordle.MaxStreak = LSdataWordle.CurrrentStreak;
  }
  LSdataWordle.WinPercentage = (
    (parseFloat(LSdataWordle.MaxStreak) /
      parseFloat(LSdataWordle.DaysPlayed)) *
    100
  ).toFixed(2);
  window.localStorage.setItem("dataWordle", JSON.stringify(LSdataWordle));
} else {
  LSdataWordle.CurrrentStreak = 0;
  window.localStorage.setItem("dataWordle", JSON.stringify(LSdataWordle));
}
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

One thing I am seeing is that you aren't recalculating the win percentage on a loss. That would be why sometimes it probably doesn't make sense for you. So take that completely out of the if statements like below, as well as the window.localstorage call seems to be independent of any conditions.

As to figure out why it won't increment on a win after losing streak, that will come down to what guessedLetters.length is and what figureGuessWordsLength is. put a breakpoint and see if they even match on a win, because the way you posted your code is as if that is a for-sure thing, but it may not be.

if (guessedLetters.length == figureGuessWordsLength) {
  LSdataWordle.CurrrentStreak++;
  if (LSdataWordle.CurrrentStreak >= LSdataWordle.MaxStreak) {
    LSdataWordle.MaxStreak = LSdataWordle.CurrrentStreak;
  }
}
else {
  LSdataWordle.CurrrentStreak = 0;
}

LSdataWordle.WinPercentage = (
    (parseFloat(LSdataWordle.MaxStreak) /
      parseFloat(LSdataWordle.DaysPlayed)) *
    100
  ).toFixed(2);
window.localStorage.setItem("dataWordle", JSON.stringify(LSdataWordle));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!