mercredi 17 novembre 2021

How do I make a program run during a set time interval (such as 14:00-16:00) in JavaScript?

I have tried this several times ever since we received it as a question in my Programming course, and everything works well, apart from the time aspect. How does one solve this?

var card = prompt("Do you have your card?")
var hour = 24


switch (card) {
  case "Yes":
    if (new Date().getHours() < 16) {
      console.log("You are allowed in")
    } else {
      console.log("You are not allowed in")
    }
    break
  case "No":
    console.log("You are not allowed in")
    break
}

Aucun commentaire:

Enregistrer un commentaire