www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] undefined

  1. #1
    Join Date
    Oct 2006
    Posts
    939

    resolved [RESOLVED] undefined

    I am sooo sorry to have to ask for help. This stupit script is supposed to loop the function schedule() until it finds a value in an Array. It does that just fine as I want it to do. The work should be done except to fill in the slots on the Arrays. Some elements are purposely left with no value as it draws a better table if I want to do that.

    So anyhow,, the function keeps adding "undefined" and I don't know where it's coming from?
    help me, please.
    Oh, the ugly code is in the upload too

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <
    HTML>
    <
    HEAD><TITLE>Tu9.8a16</TITLE>
    <
    META http-equiv=Content-Type content="text/html; charset=UTF-8">
    <
    STYLE type=text/CSS>

    </
    STYLE>

    <
    SCRIPT type="text/javascript">

    var 
    time=new Array(); var sun=new Array(); var mon=new Array(); var tue=new Array(); var wed=new Array(); var thu=new Array(); var fri=new Array(); var sat=new Array();
    time[0]='12:00am';    sun[0]='BBC World Service';    mon[0]='BBC World Service';    tue[0]='BBC World Service';    wed[0]='BBC World Service';    thu[0]='BBC World Service';    fri[0]='BBC World Service';    sat[0]='BBC World Service';
    time[1]='12:30am';    sun[1]='';    mon[1]='';    tue[1]='';    wed[1]='';    thu[1]='';    fri[1]='';    sat[1]='';
    time[2]='1:00am';    sun[2]='';    mon[2]='';    tue[2]='';    wed[2]='';    thu[2]='';    fri[2]='';    sat[2]='';
    time[3]='1:30am';    sun[3]='';    mon[3]='';    tue[3]='';    wed[3]='';    thu[3]='';    fri[3]='';    sat[3]='';
    time[4]='2:00am';    sun[4]='';    mon[4]='';    tue[4]='';    wed[4]='';    thu[4]='';    fri[4]='';    sat[4]='';
    time[5]='2:30am';    sun[5]='';    mon[5]='';    tue[5]='';    wed[5]='';    thu[5]='';    fri[5]='';    sat[5]='';
    time[6]='3:00am';    sun[6]='New Dimensions';    mon[6]='Morning Edition';    tue[6]='Morning Edition';    wed[6]='Morning Edition';    thu[6]='Morning Edition';    fri[6]='Morning Edition';    sat[6]='sat3:00am';
    time[7]='3:30am';    sun[7]='';    mon[7]='';    tue[7]='';    wed[7]='wed3:30am';    thu[7]='thu3:30am';    fri[7]='fri3:30am';    sat[7]='sat3:30am';
    time[8]='4:00am';    sun[8]='BBC World Service';    mon[8]='';    tue[8]='';    wed[8]='wed4:00am';    thu[8]='thu4:00am';    fri[8]='fri4:00am';    sat[8]='sat4:00am';
    time[9]='4:30am';    sun[9]='';    mon[9]='';    tue[9]='';    wed[9]='wed4:30am';    thu[9]='thu4:30am';    fri[9]='fri4:30am';    sat[9]='sat4:30am';
    time[10]='5:00am';    sun[10]='Weekend Edition Sunday with Liane Hansen';    mon[10]='';    tue[10]='';    wed[10]='wed5:00am';    thu[10]='thu5:00am';    fri[10]='fri5:00am';    sat[10]='sat5:00am';
    time[11]='5:30am';    sun[11]='';    mon[11]='';    tue[11]='';    wed[11]='wed5:30am';    thu[11]='thu5:30am';    fri[11]='fri5:30am';    sat[11]='sat5:30am';
    time[12]='6:00am';    sun[12]='';    mon[12]='';    tue[12]='';    wed[12]='wed6:00am';    thu[12]='thu6:00am';    fri[12]='fri6:00am';    sat[12]='sat6:00am';
    time[13]='6:30am';    sun[13]='';    mon[13]='';    tue[13]='';    wed[13]='wed6:30am';    thu[13]='thu6:30am';    fri[13]='fri6:30am';    sat[13]='sat6:30am';
    time[14]='7:00am';    sun[14]='';    mon[14]='';    tue[14]='';    wed[14]='wed7:00am';    thu[14]='thu7:00am';    fri[14]='fri7:00am';    sat[14]='sat7:00am';
    time[15]='7:30am';    sun[15]='';    mon[15]='';    tue[15]='';    wed[15]='wed7:30am';    thu[15]='thu7:30am';    fri[15]='fri7:30am';    sat[15]='sat7:30am';
    time[16]='8:00am';    sun[16]='';    mon[16]='';    tue[16]='';    wed[16]='wed8:00am';    thu[16]='thu8:00am';    fri[16]='fri8:00am';    sat[16]='sat8:00am';
    time[17]='8:30am';    sun[17]='';    mon[17]='';    tue[17]='';    wed[17]='wed8:30am';    thu[17]='thu8:30am';    fri[17]='fri8:30am';    sat[17]='sat8:30am';
    time[18]='9:00am';    sun[18]='';    mon[18]='Think Out Loud';    tue[18]='Think Out Loud';    wed[18]='Think Out Loud';    thu[18]='Think Out Loud';    fri[18]='Think Out Loud';    sat[18]='sat9:00am';
    time[19]='9:30am';    sun[19]='';    mon[19]='';    tue[19]='';    wed[19]='wed9:30am';    thu[19]='thu9:30am';    fri[19]='fri9:30am';    sat[19]='sat9:30am';
    time[20]='10:00am';    sun[20]='This American Life';    mon[20]='World Have Your Say';    tue[20]='World Have Your Say';    wed[20]='World Have Your Say';    thu[20]='World Have Your Say';    fri[20]='World Have Your Say';    sat[20]='Car Talk';
    time[21]='10:30am';    sun[21]='sun10:30am';    mon[21]='';    tue[21]='';    wed[21]='';    thu[21]='';    fri[21]='';    sat[21]='';
    time[22]='11:00am';    sun[22]='sun11:00am';    mon[22]='Talk of the Nation';    tue[22]='Talk of the Nation';    wed[22]='Talk of the Nation';    thu[22]='Talk of the Nation';    fri[22]='Science Friday';    sat[22]='sat11:00am';
    time[23]='11:30am';    sun[23]='sun11:30am';    mon[23]='';    tue[23]='tue11:30am';    wed[23]='wed11:30am';    thu[23]='thu11:30am';    fri[23]='fri11:30am';    sat[23]='sat11:30am';
    time[24]='12:00pm';    sun[24]='sun12:00pm';    mon[24]='';    tue[24]='tue12:00pm';    wed[24]='wed12:00pm';    thu[24]='thu12:00pm';    fri[24]='fri12:00pm';    sat[24]='sat12:00pm';
    time[25]='12:30pm';    sun[25]='sun12:30pm';    mon[25]='';    tue[25]='tue12:30pm';    wed[25]='wed12:30pm';    thu[25]='thu12:30pm';    fri[25]='fri12:30pm';    sat[25]='sat12:30pm';
    time[26]='1:00pm';    sun[26]='sun1:00pm';    mon[26]='The World - Early Edition';    tue[26]='tue1:00pm';    wed[26]='wed1:00pm';    thu[26]='thu1:00pm';    fri[26]='fri1:00pm';    sat[26]='sat1:00pm';
    time[27]='1:30pm';    sun[27]='sun1:30pm';    mon[27]='';    tue[27]='tue1:30pm';    wed[27]='wed1:30pm';    thu[27]='thu1:30pm';    fri[27]='fri1:30pm';    sat[27]='sat1:30pm';
    time[28]='2:00pm';    sun[28]='sun2:00pm';    mon[28]='Fresh Air';    tue[28]='tue2:00pm';    wed[28]='wed2:00pm';    thu[28]='thu2:00pm';    fri[28]='fri2:00pm';    sat[28]='sat2:00pm';
    time[29]='2:30pm';    sun[29]='sun2:30pm';    mon[29]='';    tue[29]='tue2:30pm';    wed[29]='wed2:30pm';    thu[29]='thu2:30pm';    fri[29]='fri2:30pm';    sat[29]='sat2:30pm';
    time[30]='3:00pm';    sun[30]='sun3:00pm';    mon[30]='The World';    tue[30]='tue3:00pm';    wed[30]='wed3:00pm';    thu[30]='thu3:00pm';    fri[30]='fri3:00pm';    sat[30]='sat3:00pm';
    time[31]='3:30pm';    sun[31]='sun3:30pm';    mon[31]='';        tue[31]='tue3:30pm';    wed[31]='wed3:30pm';    thu[31]='thu3:30pm';    fri[31]='fri3:30pm';    sat[31]='sat3:30pm';
    time[32]='4:00pm';    sun[32]='sun4:00pm';    mon[32]='All Things Considered';    tue[32]='tue4:00pm';    wed[32]='wed4:00pm';    thu[32]='thu4:00pm';    fri[32]='fri4:00pm';    sat[32]='sat4:00pm';
    time[33]='4:30pm';    sun[33]='sun4:30pm';    mon[33]='';        tue[33]='tue4:30pm';    wed[33]='wed4:30pm';    thu[33]='thu4:30pm';    fri[33]='fri4:30pm';    sat[33]='sat4:30pm';
    time[34]='5:00pm';    sun[34]='sun5:00pm';    mon[34]='';        tue[34]='tue5:00pm';    wed[34]='wed5:00pm';    thu[34]='thu5:00pm';    fri[34]='fri5:00pm';    sat[34]='sat5:00pm';
    time[35]='5:30pm';    sun[35]='sun5:30pm';    mon[35]='';        tue[35]='tue5:30pm';    wed[35]='wed5:30pm';    thu[35]='thu5:30pm';    fri[35]='fri5:30pm';    sat[35]='sat5:30pm';
    time[36]='6:00pm';    sun[36]='sun6:00pm';    mon[36]='';        tue[36]='tue6:00pm';    wed[36]='wed6:00pm';    thu[36]='thu6:00pm';    fri[36]='fri6:00pm';    sat[36]='sat6:00pm';
    time[37]='6:30pm';    sun[37]='sun6:30pm';    mon[37]='Marketplace';    tue[37]='tue6:30pm';    wed[37]='wed6:30pm';    thu[37]='thu6:30pm';    fri[37]='fri6:30pm';    sat[37]='sat6:30pm';
    time[38]='7:00pm';    sun[38]='sun7:00pm';    mon[38]='Fresh Air';    tue[38]='tue7:00pm';    wed[38]='wed7:00pm';    thu[38]='thu7:00pm';    fri[38]='fri7:00pm';    sat[38]='sat7:00pm';
    time[39]='7:30pm';    sun[39]='sun7:30pm';    mon[39]='';        tue[39]='tue7:30pm';    wed[39]='wed7:30pm';    thu[39]='thu7:30pm';    fri[39]='fri7:30pm';    sat[39]='sat7:30pm';
    time[40]='8:00pm';    sun[40]='sun8:00pm';    mon[40]='On the Media';    tue[40]='tue8:00pm';    wed[40]='wed8:00pm';    thu[40]='thu8:00pm';    fri[40]='fri8:00pm';    sat[40]='sat8:00pm';
    time[41]='8:30pm';    sun[41]='sun8:30pm';    mon[41]='';        tue[41]='tue8:30pm';    wed[41]='wed8:30pm';    thu[41]='thu8:30pm';    fri[41]='fri8:30pm';    sat[41]='sat8:30pm';
    time[42]='9:00pm';    sun[42]='sun9:00pm';    mon[42]='Think Out Loud  The Writers Almanac';    tue[42]='tue9:00pm';    wed[42]='wed9:00pm';    thu[42]='thu9:00pm';    fri[42]='fri9:00pm';    sat[42]='sat9:00pm';
    time[43]='9:30pm';    sun[43]='sun9:30pm';    mon[43]='';        tue[43]='tue9:30pm';    wed[43]='wed9:30pm';    thu[43]='thu9:30pm';    fri[43]='fri9:30pm';    sat[43]='sat9:30pm';
    time[44]='10:00pm';    sun[44]='sun10:00pm';    mon[44]='BBCs The World Today';    tue[44]='tue10:00pm';    wed[44]='wed10:00pm';    thu[44]='thu10:00pm';    fri[44]='fri10:00pm';    sat[44]='sat10:00pm';
    time[45]='10:30pm';    sun[45]='sun10:30pm';    mon[45]='';        tue[45]='tue10:30pm';    wed[45]='wed10:30pm';    thu[45]='thu10:30pm';    fri[45]='fri10:30pm';    sat[45]='sat10:30pm';
    time[46]='11:00pm';    sun[46]='sun11:00pm';    mon[46]='BBC World Service';    tue[46]='tue11:00pm';    wed[46]='wed11:00pm';    thu[46]='thu11:00pm';    fri[46]='fri11:00pm';    sat[46]='sat11:00pm';
    time[47]='11:30pm';    sun[47]='sun11:30pm';    mon[47]='BBC World Service';    tue[47]='tue11:30pm';    wed[47]='wed11:30pm';    thu[47]='thu11:30pm';    fri[47]='fri11:30pm';    sat[47]='sat11:30pm';


        var 
    arr=[sun,mon,tue,wed,thu,fri,sat,time]
        var 
    d=new Date(); var day=d.getDay();  var min=d.getMinutes();
         var 
    a=Math.round(d.getHours()+(min/60))*2;  
    function 
    schedule(hour,dd){
      if(
    hour==arr[day].length){hour=0}

        if(
    arr[day][hour]){    document.getElementById(dd).innerHTML'<b>'+time[hour]+'</b> '+arr[day][hour]+'* ';  }
        else{
             if(
    dd=='previoushour'){hour=hour-1;schedule(hour,'previoushour')}
            else if(
    dd=='nowhour'){hour=hour-1;schedule(hour,'nowhour')}
            else if(
    dd=='nexthour'){hour=hour+1schedule(hour,'nexthour')}
            }
    }


    </SCRIPT>
    <META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
    <BODY scroll="auto">

    <span id="previoushour" class="sched" ><script>    document.write(    schedule(a-1,'previoushour')    )
    </script></span><br>
    <span id="nowhour" class="sched"><script>    document.write(    schedule(a,'nowhour')    )
    </script></span><br>
    <span id="nexthour" class="sched" ><script>    document.write(    schedule(a+1,'nexthour')    )
    </script></span>


    </BODY></HTML> 
    Attached Files Attached Files

  2. #2
    Join Date
    Oct 2008
    Location
    U.S.
    Posts
    726
    You are document.write'ing a function which does not return a value. Also, your script tags in the body do not have the required type="text/javascript" in them.
    Change this:
    <span id="previoushour" class="sched" ><script> document.write( schedule(a-1,'previoushour') )
    </script></span><br>
    <span id="nowhour" class="sched"><script> document.write( schedule(a,'nowhour') )
    </script></span><br>
    <span id="nexthour" class="sched" ><script> document.write( schedule(a+1,'nexthour') )
    </script></span>
    To this:

    Code:
    <span id="previoushour" class="sched" ></span><br> 
    <span id="nowhour" class="sched"></span><br> 
    <span id="nexthour" class="sched" ></span>
    Then in the head script, add this in:

    Code:
    window.onload = function () {
        schedule(a - 1, 'previoushour');
        schedule(a,'nowhour');
        schedule(a + 1,'nexthour');
    };

  3. #3
    Join Date
    Oct 2008
    Location
    U.S.
    Posts
    726
    which does not return a value
    Actually, the value of a function which does not implicity return a value is undefined, thus the undefined was being written because that is the value of function which does not return a value.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles