• 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.
    • 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.

HTML & CSS Radio on-air script

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>
 

cbreemer

King Coder
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 ?
 

strawbs89

Active Coder
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
 

cbreemer

King Coder
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 ?
 

cbreemer

King Coder
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 ?
 
Top