This entire HTML’s script code:
[...document.querySelectorAll("input")].forEach(ele => {
ele.addEventListener(
"change", () => {
Main();
}
);
});
function Main() {
document.getElementById("Output").textContent = ""
[...document.querySelectorAll("*.HiddenMsg")].forEach(ele => ele.hidden = true)
try {
let DatesWrong = false
let StartDate = new Date(document.getElementById("Input_DateTimeStart").value)
if (StartDate.toString() == "Invalid Date") {
document.getElementById("Input_DateTimeStart_ErrorMsg").hidden = false
DatesWrong = true
}
let EndDate = new Date(document.getElementById("Input_DateTimeEnd").value)
if (EndDate.toString() == "Invalid Date") {
document.getElementById("Input_DateTimeEnd_ErrorMsg").hidden = false
DatesWrong = true
}
if (DatesWrong) {
return
}
let TimeDiff = EndDate.valueOf() - StartDate.valueOf()
if (TimeDiff < 0) {
document.getElementById("Output").textContent = "End date before start."
return
}
let DurationString = DisplayTimeDuration(TimeDiff)
document.getElementById("Output").textContent = "Duration: " + DurationString + " (" + TimeDiff.toFixed(0) + " ms)"
} catch {
return
}
}
function DisplayTimeDuration(Duration) {
let OutputString = ""
Duration = Math.abs(Duration)
let UnitsOfTimeArray = []
let Seconds = Math.floor(Duration/1000)
UnitsOfTimeArray.unshift({Unit: Seconds % 60, UnitName: "s"})
let Minute = Math.floor(Seconds/60)
UnitsOfTimeArray.unshift({Unit: Minute % 60, UnitName: "m"})
let Hour = Math.floor(Minute/60)
UnitsOfTimeArray.unshift({Unit: Hour % 24, UnitName: "h"})
let Day = Math.floor(Hour/24)
UnitsOfTimeArray.unshift({Unit: Day, UnitName: "d"})
let LeadingUnitIsNonZero = false
for (let i = 0; i < UnitsOfTimeArray.length; i++) {
if (UnitsOfTimeArray[i].Unit != 0) {
LeadingUnitIsNonZero = true //Once it's true, stays true. All remaining units are significant
}
if (LeadingUnitIsNonZero || i == UnitsOfTimeArray.length-1) {
OutputString += UnitsOfTimeArray[i].Unit + UnitsOfTimeArray[i].UnitName
if (i != UnitsOfTimeArray.length-1) {
OutputString += " "
}
}
}
return OutputString
}
The code [...document.querySelectorAll("*.HiddenMsg")].forEach(ele => ele.hidden = true)
, for whatever reason, errors out saying Uncaught SyntaxError: Unexpected token '...'
, however, when I change that line of code to have a identifier like this: let test = [...document.querySelectorAll("*.HiddenMsg")].forEach(ele => ele.hidden = true)
, it works fine. Any idea why this bug false-positively say there’s a syntax error with the spread syntax? The very literal first line of code have no issues whatsoever.