function setTheme(theme) { localStorage.setItem("theme",theme); var root = document.querySelector(":root"); var rootstyle = getComputedStyle(root); const black = rootstyle.getPropertyValue("--black"); const white = rootstyle.getPropertyValue("--white"); var bgcol; var fgcol; if (theme === "dark") { bgcol = black; fgcol = white; } else if (theme === "light") { bgcol = white; fgcol = black; } else { setTheme("dark"); return; } root.style.setProperty("--backgroundColour",bgcol); root.style.setProperty("--foregroundColour",fgcol); }