O sposti il blocco script sotto il tag span oppure il timer devi eseguirlo all'evento onload del documento.