-4

I need to create a countdown that runs daily from 8am to 8pm Monday-Friday and 8am-6pm Saturday and Sunday and then when it's finished, says something like 'We open tomorrow at 8am!'

How can I achieve this?

Website: (you can see where the countdown would be.)

http://www.securemyhome.com/test-pulse3

HTML

 <div class="wereOpen"><span class="blue">We'll Call You!</span><br />Only 
 <span class="countdown">
 <!--  COUNTDOWN BANNER  -->
        7 hours 
        35 minutes 
</span> left!</div>

Here's a few i've tried.

var count=30;

var counter=setInterval(timer, 1000); //1000 will  run it every 1 second

function timer()
{
count=count-1;
if (count <= 0)
{
 clearInterval(counter);
 //counter ended, do something here
 return;
 }

 //Do code for showing the number of seconds here
 }

2

 function Countdown(options) {
  var timer,
 instance = this,
   seconds = options.seconds || 10,
 updateStatus = options.onUpdateStatus || function () {},
 counterEnd = options.onCounterEnd || function () {};

 function decrementCounter() {
 updateStatus(seconds);
 if (seconds === 0) {
  counterEnd();
  instance.stop();
   }
   seconds--;
  }

  this.start = function () {
  clearInterval(timer);
   timer = 0;
  seconds = options.seconds;
  timer = setInterval(decrementCounter, 1000);
  };

  this.stop = function () {
   clearInterval(timer);
  };
 }
GSaunders
  • 548
  • 1
  • 5
  • 15
  • 4
    *"anything else needed"* ... yes, some kind of attempt. – Emissary Jan 31 '14 at 20:08
  • What have you tried so far? There are plenty of countdown plugins out there if you want a pre-made solution. – badAdviceGuy Jan 31 '14 at 20:08
  • If you have so litte knowledge in JS that you can't even *attempt* anything, you probably shouldn't turn to this site for help. – display-name-is-missing Jan 31 '14 at 20:09
  • I have tried a few but I can't find any that are set to daily times like 8am-8pm M-F and 8am-6pm S-S. Most countdowns seem to be to a specific date and do not restart daily. – GSaunders Jan 31 '14 at 20:09
  • You're going to need to increase your knowledge of java script if you expect to do something like this. Even if someone spends the time to write a method for you, how will you support it if you don't understand it? – Rick S Jan 31 '14 at 20:10
  • I can do basic functions of Javascript, like if you scroll down on the site you'll see how the header bar changes. However, I do not have enough knowledge to create whatever I need. (If that makes sense) – GSaunders Jan 31 '14 at 20:11
  • That is why Rick said you should increase your knowledge of javascript. SO isn't designed for people to just write your code for you, when you haven't shown any effort. – forgivenson Jan 31 '14 at 20:15
  • @forgivenson I have messed with three or so Javascript and jQuery codes, but I can't seem to get it to be a daily thing – GSaunders Jan 31 '14 at 20:16
  • Then post what you have tried, with a specific question about where you are having an issue. – forgivenson Jan 31 '14 at 20:18
  • @forgivenson, I have. – GSaunders Jan 31 '14 at 20:22
  • @Emissary I posted the scripts to my first two attempts at it, I wouldn't have asked here if I hadn't already attempted for two days. – GSaunders Jan 31 '14 at 20:24
  • You've done sod all - [example 1](http://stackoverflow.com/a/1191875/1238344) and [example 2](http://stackoverflow.com/a/1192001/1238344) have been blatantly copied from the same question and don't even remotely correlate to your HTML - we are not stupid and we are not amused. – Emissary Jan 31 '14 at 20:32
  • @Emissary, those are the scripts I had previously taken and tried to implement into my site. Obviously, I had changed the codes to correlate with mine. – GSaunders Jan 31 '14 at 20:33
  • Look the bottom line is Stack is a site for learning - it doesn't matter if it doesn't work - the point is that if you explain what **YOU** have tried and what errors you encounter people will be more inclined to help you understand where and why you are going wrong. – Emissary Jan 31 '14 at 20:35

1 Answers1

2

Since everyone is ripping you apart and being of no help, here's a code that is similar to what you may want. Adjust accordingly.

// 24 hour based
var targetHour = 10;

var currentTime = new Date();

// sun 0 mon 1 ... fri 5 sat 6
var currentDay = currentTime.getDay();

var offset = 24;
                // friday
if (currentDay === 5) {
    offset = 60;
}              // saturday
else if(currentDay === 6) {                                                                   
    offset = 48;
}

if(currentTime.getHours() > targetHour) {
    console.log('hours:', (targetHour + offset) - currentTime.getHours() - 1);
    console.log('minutes:', 60 - currentTime.getMinutes());
} 
else if(currentTime.getHours() < targetHour) {
    console.log(targetHour - currentTime.getHours() - 1);
    console.log('minutes:', 60 - currentTime.getMinutes());
} 
GrayJ
  • 96
  • 7
  • 1
    No one is ripping anyone, these are the rules of Stack Overflow - blatant code requests are no benefit to anyone but self-serving posters who have no interest in learning and only serve to perpetuate a cycle that is polluting the site and diluting it's quality as a learning resource. – Emissary Jan 31 '14 at 20:40