From d37c2c45e60b453755f894f6d4ddc640634a658f Mon Sep 17 00:00:00 2001 From: Lavender Date: Tue, 4 May 2021 20:19:04 -0700 Subject: [PATCH] Improve code --- main.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/main.js b/main.js index 59826c8..cb8b671 100644 --- a/main.js +++ b/main.js @@ -1,3 +1,5 @@ +"use strict" + let request = new XMLHttpRequest() request.open( "GET", @@ -34,21 +36,23 @@ request.onload = function() { ) // Set the toggle function for & display the checkbox - shadows.oninput = shadows_on = function() { - results_shadowed.style.display = "block" - results.style.display = "none" - // Toggle off function - shadows.oninput = function() { - results.style.display = "block" - results_shadowed.style.display = "none" - shadows.oninput = shadows_on - } - } + shadows.oninput = checkbox_toggle shadows.style.display = "block" document.getElementById("progress").remove() } +function checkbox_toggle() { + results_shadowed.style.display = "block" + results.style.display = "none" + // Toggle off function + shadows.oninput = function() { + results.style.display = "block" + results_shadowed.style.display = "none" + shadows.oninput = checkbox_toggle + } +} + function display_teams(totals, teams, div_container, hitters_fn, pitchers_fn) { const ENDING = x => (Math.abs(x) === 1 ? "" : "s") // Make the headers & lists for teams @@ -58,7 +62,7 @@ function display_teams(totals, teams, div_container, hitters_fn, pitchers_fn) { div_container.insertAdjacentHTML("afterbegin", `

${total} player${ENDING(total)}

`) - }) + }) // Put the teams in the lists teams.forEach(function(team, pos) { let hitters = hitters_fn(team)