Why I am Banned from Fantasy Hockey?

0 Alex Carter · April 6, 2015
Guys, could anyone explain me what happened here and why did it actually showed the best player?

if( ppg > bestPPG ) {
bestPPG = ppg;
bestPlayer = player;
}
It's Bucky's tutorial here https://www.thenewboston.com/videos.php?cat=14&video=20058

Post a Reply

Replies

Oldest  Newest  Rating
+1 Brian Reed · April 6, 2015
Hi Alex,

I just watched the video and the code you have shown is not exactly the same.
Missing are the index variables for the ppg and player arrays.

So, now the explanation:
This if function is inside of a for loop, and tests if (ppg > bestPPG) each time.
The first time through i is 0 and bestPPG is 0 as was originally set.  Note: ppg[0] belongs to player[0]

The first time the test is true, and the body of the if function is executed and bestPPG will update to the value of ppg, and bestPlayer will be the value of player. Next it's back to the top of the for loop to run through again incrementing i each time until the for loop condition is no longer true. However, should the if function test false, nothing in the body of the function is executed and nothing is updated. Therefore, this will only keep the last highest ppg value that tested true by making it the bestPPG found during the loop.

Cheers,
Brian
0 Adrian Fab · April 12, 2015
Brian Reed, what does "BestPPG" mean in English? I mean the word, I didn't understant that part of the video when he pronounces it.
0 Brian Reed · April 13, 2015
Hi Adrian,

Best Points Per Game

Understanding the code someone else writes can be difficult to interpret, that's why it's good practice to include //comments when writing your own code for both you and anyone else reading it later on.

 Albeit, maybe not so much for these tutorials.


Cheers,
Brian
  • 1

C

107,273 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator