function Alarm(clock) { Clock.call(this, clock); this.clock.querySelector('.set-alarm').onchange = () => { let timer = clock.querySelector('.set-alarm').value.split(':'); let hour = timer[0]; let minute = timer[1]; let second = timer[2]; this.newDate = new Date(0, 0, 0, hour, minute, second).getTime(); }; console.log(second); } 

How to get the variable second or this.newDate so that you can output it to console.log?

Reported as a duplicate at Grundy. javascript Nov 6 '18 at 6:05 pm

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • Try console.log(this.newDate); like this console.log(this.newDate); - Stepan Kasyanenko
  • In the sense of "get"? There she is ready, take it and take it anywhere. - Enikeyschik
  • did not help ..... - Test
  • when I write console.log (this.newDate) displays undefined - Test
  • one
    because values ​​are assigned only after the onchange event is onchange , and console.log is called right away - ThisMan

1 answer 1

console.log () inside onchange and everything should work or what kind of perversions with promises / callbacks

 this.clock.querySelector('.set-alarm').onchange = () => { let timer = clock.querySelector('.set-alarm').value.split(':'); let hour = timer[0]; let minute = timer[1]; let second = timer[2]; this.newDate = new Date(0, 0, 0, hour, minute, second).getTime(); console.log(second); };