samedi 14 octobre 2017

Alerts set on a timer but only if box is checked

I need an alert to pop up at a given minute past every hour, but only if a box is checked. Keep in mind everything in the here needs to be duplicated as on this page. I seem to have the timers working, but for the last 2 days I have been unable to make the alerts only happen if the box is checked for each individual city.

window.onload = function() {
  var LAA = document.querySelector('input[name=LAAlert]');
  var d = new Date();
  var Gamehours = d.getUTCHours();
  var Gameminutes = d.getUTCMinutes();
  var Gameseconds = d.getUTCSeconds();
  //LA Variables


  function check() {
    var LAcheck;
    var LACoke = "20";
    var LAHeroin = "0";
    var LABarbs = "05";
    var LAUntilcoke = LACoke - Gameminutes;
    var LANextcoke = LAUntilcoke + 60;
    var LAUntilheroin = 60 - Gameminutes;
    var LAUntilbarb = LABarbs - Gameminutes;
    var LANextbarb = LAUntilbarb + 60;
    if (LAA.checked) {
      LAcheck = "checked";
    } else {
      LAcheck = "not checked";
    }
    document.getElementById('LAAresult').innerHTML = 'LA Alerts ' + LAcheck;

    //LA Timer Alerts
    if (LAcheck == "checked" && Gameminutes == LACoke && Gameseconds == "00") {
      window.alert("The Price of Cocaine in LA has changed")
    };

    if (LAcheck == "checked" && Gameminutes == LAHeroin && Gameseconds == "00") {
      window.alert("The Price of Heroin in LA has changed")
    };

    if (LAcheck == "checked" && Gameminutes == LABarbs) {
      window.alert("The Price of Barbituates in LA has changed")
    };
  }
  LAA.onchange = check;
  check();
}


var myVar = setInterval(function() {
  myTimer()
}, 1000);

function myTimer() {
  var d = new Date();
  var Gamehours = d.getUTCHours();
  var Gameminutes = d.getUTCMinutes();
  var Gameseconds = d.getUTCSeconds();
  var Countdown = 60 - Gameseconds;

  //LA Variables
  var LACoke = "20";
  var LAHeroin = "00";
  var LABarbs = "05";
  var LAUntilcoke = LACoke - Gameminutes;
  var LANextcoke = LAUntilcoke + 60;
  var LAUntilheroin = 60 - Gameminutes;
  var LAUntilbarb = LABarbs - Gameminutes;
  var LANextbarb = LAUntilbarb + 60;



  //Display In-game time
  document.getElementById("gametime").innerHTML = "Time: " + Gamehours + ":" + Gameminutes + ":" + Gameseconds;
  //LA Timers     

  //Display Cocaine price change time remaining
  if (LACoke > Gameminutes) {
    document.getElementById("LAcoketime").innerHTML = "Cocaine: " + LAUntilcoke + ":" + Countdown;
  } else if (LACoke < Gameminutes) {
    document.getElementById("LAcoketime").innerHTML = "Cocaine: " + LANextcoke + ":" + Countdown;
  } else if (LACoke == Gameminutes) {
    document.getElementById("LAcoketime").innerHTML = "Cocaine: CHANGED";
  };


  //Display Heroin price change time remaining
  if (LAHeroin < Gameminutes) {
    document.getElementById("LAherointime").innerHTML = "Heroin: " + LAUntilheroin + ":" + Countdown;
  } else if (LAHeroin == Gameminutes) {
    document.getElementById("LAherointime").innerHTML = "Heroin: CHANGED";
  };


  //Display Cocaine price change time remaining
  if (LABarbs < Gameminutes) {
    document.getElementById("LAbarbtime").innerHTML = "Barbituates: " + LANextbarb + ":" + Countdown;
  } else if (LABarbs == Gameminutes) {
    document.getElementById("LAbarbtime").innerHTML = "Barbituates: CHANGED";
  } else if (LABarbs > Gameminutes) {
    document.getElementById("LAbarbtime").innerHTML = "Barbituates: " + LAUntilbarb + ":" + Countdown;
  };

}
<p id="gametime"></p>
<input name="LAAlert" id="LAALert" type="checkbox" value="1"><span id="LAAresult"></span>
<p id="LAbarbtime"></p>
<p id="LAherointime"></p>
<p id="LAcoketime"></p>
<br>



Aucun commentaire:

Enregistrer un commentaire