8
I need to make a validation if a value has a difference of up to 5, both for positive and negative. I wonder if there is any Javascript function that helps me in this, without having to do the following if
giant:
let scoreboard_local_team = 22;
let scoreboard_visiting_team = 26;
let points = 0;
if (
scoreboard_local_team + 1 === scoreboard_visiting_team ||
scoreboard_local_team + 2 === scoreboard_visiting_team ||
scoreboard_local_team + 3 === scoreboard_visiting_team ||
scoreboard_local_team + 4 === scoreboard_visiting_team ||
scoreboard_local_team - 1 === scoreboard_visiting_team ||
scoreboard_local_team - 2 === scoreboard_visiting_team ||
scoreboard_local_team - 3 === scoreboard_visiting_team ||
scoreboard_local_team - 4 === scoreboard_visiting_team
) {
points += 30;
}
console.log(points)