Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

strawbs89

Active Coder
hi i'm having problems with my script
it won't show my djimages when my staff are on air

"could someone please possible help"

here's my js script


Code:
(function( d ) {
   'use strict';
function onair(){
 
   var dj = d.querySelector('#dj'),
       nd = new Date(),
       dy = nd.getDay(),
       hr = nd.getHours(),
       mn = nd.getMinutes();

if(( dy === 7 && hr === 18 && mn >=20 )||
   ( dy === 4 && hr === 18 && mn <=20 )||
    {
     dj.src='djimages/strawbs.png';
 }
else {
if(( dy === 5 && hr === 13 && mn <=59 )||
   ( dy === 5 && hr === 14 && mn <=59 )) {
     dj.src='djimages/deano.png';
 }
else {
if(( dy === 6 && hr === 8 && mn <=59 )||
   ( dy === 6 && hr === 9 && mn <=59 )) {
     dj.src='djimages/kayley.png';
 }
else {
     dj.src='djimages/off-air.jpg';
    }
   }
  }
 }

setInterval( function(){ onair();}, 1000 );
}( document ));


also here's html script

Code:
<div align="center"><html>
<head>
<style>
p.one {
  border-style: double;
  border-color: white;
  width: 256px;
  height: 144px
 
}
</style>
</head>
<body>



<p class="one"><link rel="stylesheet" href="css/screen.css" media="screen">
            <noscript>
<p>JavaScipt needs to be enabled for this page to function correctly</p>
</noscript>

<img id="dj" src="images/off-air.jpg" alt="Off-line" name="refresh" width="256" height="144">

<script src="scripts/showdj.js"></script></div></p>

</body>
</html>
 
On first glance that looks like it should work, though I'm not quite sure the js is complete, and what's that <div> doing at the start of the html ?
Have you verified that the onair() function is periodically called ? And have you tested these if statements, using manual input for dy, hr and mn ?
 
On first glance that looks like it should work, though I'm not quite sure the js is complete, and what's that <div> doing at the start of the html ?
Have you verified that the onair() function is periodically called ? And have you tested these if statements, using manual input for dy, hr and mn ?
nope haven't tested hoping someone here would, also that div is centring the on-air script
 
nope haven't tested hoping someone here would, also that div is centring the on-air script
Well hmmmm... you expect someone else to do your testing and debugging ? That is not the way to go about it.
And a <div> to "center a script" ? Can you explain how you expect that to work ? Even apart from the fact it's outside the <body> which is against the basic HTML rules ?
 
I'm very surprised that <div> does anything at all. Even though it seems to work for you it is WRONG ! It should be inside the <body>. Also you should not be using align, it's obsolete. Use CSS instead. You should run the html though an online validator so you can see the various issues.

but how should the script work

Your script should work like you intend it to work 🙄 Right now it won't work at all as there is a glaring error in it.
If only you took the trouble to do some testing and debugging, you would have found it already. But you don't believe in that, do you ?
 
I'm very surprised that <div> does anything at all. Even though it seems to work for you it is WRONG ! It should be inside the <body>. Also you should not be using align, it's obsolete. Use CSS instead. You should run the html though an online validator so you can see the various issues.



Your script should work like you intend it to work 🙄 Right now it won't work at all as there is a glaring error in it.
If only you took the trouble to do some testing and debugging, you would have found it already. But you don't believe in that, do you ?
so what could i do if i want to add more days it's only got dy=1 for monday




Code:
(function( d ) {
   'use strict';
function onair(){
 
   var dj = d.querySelector('#dj'),
       nd = new Date(),
       dy = nd.getDay(),
       hr = nd.getHours(),
       mn = nd.getMinutes();

if ( dy === 4 && hr === 20 && mn <=12 ) {
   ( dy === 4 && hr === 7 && mn <=19 )||
   ( dy === 4 && hr === 6 && mn >=20 )||
   ( dy === 4 && hr === 3 && mn <=19 )
     dj.src='images/strawbs.gif';
 }
else {
if(( dy === 5 && hr === 13 && mn <=59 )||
   ( dy === 5 && hr === 14 && mn <=59 )) {
     'Friday at 10 AM<br>Christian Music<br>with Dj Bunny';
 }
else {
if(( dy === 6 && hr === 8 && mn <=14 )||
   ( dy === 6 && hr === 9 && mn <=15 )) {
     'Saturday at 8 AM<br>Christian Music<br>with Dj Bunny';
 }
 else {
if(( dy === 1 && hr === 8 && mn <=14 )||
   ( dy === 1 && hr === 8 && mn <=15 )) {
     dj.src='images/kayley.jpg';
 }
else {
     dj.src='images/off-air.png';
 
    }
   }
  }
 }

setInterval( function(){ onair();}, 1000 );
}
}( document )) ;
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom