Skip to content

Commit d0ffe37

Browse files
committed
Fix scoring algorithm
1 parent 0076704 commit d0ffe37

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

app.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ const game = () => {
5959
Math.max(guess, 1) / Math.max(secret, 1),
6060
Math.max(secret, 1) / Math.max(guess, 1),
6161
) *
62-
(1 - Math.abs(secret - guess) / maxGuess); //increase level score
62+
(1 - Math.abs(secret - guess) / maxGuess) *
63+
(guess < secret
64+
? guess / secret
65+
: (maxGuess - guess + 1) / (maxGuess - secret + 1)); //increase level score
6366
attempts++;
6467
if (attempts >= maxAttempts) {
6568
//if all attempts used reset game to initial state
@@ -85,6 +88,7 @@ const game = () => {
8588
//if guess is equal to secret number
8689
feedbackText.textContent =
8790
"You guessed correctly! +" + levelScore + " points!";
91+
levelScore += maxGuess;
8892
score += Math.round(
8993
((levelScore * (maxAttempts - attempts + 1)) / (attempts + 1)) *
9094
maxAttempts,

0 commit comments

Comments
 (0)