O
O
olya_0972018-02-25 15:02:33
JavaScript
olya_097, 2018-02-25 15:02:33

What does the highlighted line that starts with if do?

//Запускает таймер
    function go(){
      window.timerId = window.setInterval(timer, 1000);
    }
    function timer(){
      if(window.number == undefined || window.number == 3) {
      window.number = 1;
      } else window.number = window.number + 1;
      var img = document.getElementById('img');
      img.src = 'smiles/'+window.number+'.png'
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kreotech, 2018-02-25
@olya_097

I think it should be understood like this:
If the property "window.number" does not exist or is equal to 3 ,
then set this property to 1 ,
otherwise add 1 to the existing value .

B
Bhudh, 2018-02-25
@Bhudh

Loops the counter of pictures, and also initiates it in case of absence. The latter, by the way, is bad practice.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question