Schedule in JavaScript

0

I have to generate a list of hours between 10:00 and 19:30 in minutes of 30 minutes with a for loop. (eg 10:00 - 10:30 - 11:00 ......)

At the moment I've done it like that but I do not think it's well done.

for (var i=10; i<20; i++){

    document.write(i + ":00 " + i + "" + ":30" + " ");          
}
    
asked by InThaHouse 28.09.2018 в 13:46
source

2 answers

2

You can use the Date type and work on the minutes. Then show hour and minutes. For example:

var now = new Date('2018-09-28T10:00:00');
    
    for(var i = 0; i < 19; i++){
    now.setMinutes(now.getMinutes() + 30);
    console.log(now.getHours() + ":" + ("00" + now.getMinutes()).slice(-2));
    }
    
answered by 28.09.2018 / 14:05
source
0

The code does what you want.

can you read the code better like this:

for (var i=10; i<20; i++){

  document.write(i + ":00 " + i + ":30 " );          
}

or like this:

for (var i=10; i<20; i++){

  document.write(i + ":00 "); 
  document.write(i + ":30 ");  
}
    
answered by 28.09.2018 в 14:07