Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I need to se how many times the next number is greater than the before one

function gameHistory(gamePoints){

    let points = gamePoints.split(", ")
    let recordBreak = 0;
    let bestPoint = points[0];

    for(let i = 1; i<points.length; i++){
        
        if(points[i]>bestPoint){

            bestPoint = points[i]
            recordBreak = recordBreak + 1;
            
        }

    }
    return console.log(recordBreak) 

     /*
      the console shows 2, was spected three, because we 
    have three times that the player beated the records:
    10 to 12,
    12 to 15,
    15 to 20. 
     */

}

gameHistory("10, 12, 8, 15, 20")  //I used this game results for example

>Solution :

The code is comparing strings after the split. Change them to numbers with a map…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

let points = gamePoints.split(", ").map(str => +str);
function gameHistory(gamePoints) {
  let points = gamePoints.split(", ").map(str => +str);
  let recordBreak = 0;
  let bestPoint = points[0];

  for (let i = 1; i < points.length; i++) {
    if (points[i] > bestPoint) {
      bestPoint = points[i]
      recordBreak = recordBreak + 1;
    }
  }
  return recordBreak

  /*
      the console shows 2, was spected three, because we 
    have three times that the player beated the records:
    10 to 12,
    12 to 15,
    15 to 20. 
     */

}

console.log(gameHistory("10, 12, 8, 15, 20"))
//I used this game results for example
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading