DEV Community

Discussion on: Time conversion

Collapse
 
rcalvanese profile image
rcalvanese

Actually, I am pretty sure this will error. You cannot reassign a value to hour once it has been assigned the value of "07". "Uncaught SyntaxError: Identifier 'hour' has already been declared"

Thread Thread
 
kecbm profile image
Klecianny Melo

Hi @rcalvanese, how are you? How did you run the code? Was it with another string for the time in the constant "s"?

Thread Thread
 
rcalvanese profile image
rcalvanese

Hi! I ran it here jsfiddle.net/cx9pa41n/

Thread Thread
 
kecbm profile image
Klecianny Melo

Hi! I understood. You can replace const with var in this line to resolve this error: var [hour, minute, second] = s.slice(0,8).split(':');