I want to make the progress bar in my game responsive to changes in the winning score. Currently, it moves from 0% to 100%, which is equivalent to 100 points - the default winning score. But I need the progress bar to adjust accordingly based on the user-inputted winning score. For example, if the winning score is set to 50 points, reaching a score of 25 should display the player as halfway towards winning (50%). Can you help me figure out how to program this feature for the progress bar? I hope my explanation is clear.
HTML input:
<input class="score-input" type="text">
Function to set the winning score (default is 100):
function setWinningScore() {
let inputScore = document.querySelector('.score-input').value;
if (inputScore) {
winningScore = inputScore;
} else {
winningScore = 100;
}
}
Progress bar function that updates based on player's score and the progress bar element's ID:
function progressBar(myScore, progBarId) {
progBarId.style.height = myScore + '%';
}