I have an objeft date question in JS

Discussion in 'JavaScript' started by progfrog, Jan 10, 2008.

  1. #1
    <html>
    <h1>what is the time</h1>


    <script language="javascript" type="text/javascript">



    var now=new Date();
    var Mhour=now.getHour();
    if (Mhour>12)
    {
    Mhour-=12;
    }

    var Mminute=now.getMinute();
    if (Mminute.length==1)

    {
    Mminute="0" + Mminute;
    }

    document.write =(Mhour + ":" + Mminute);



    function MyHour()

    {

    if (Mhour<=9)
    document.writeln("you can still sleep")
    else
    if(Mhour<=17)
    document.writeln("you should work")

    else
    document.writeln("evening time")

    }

    </script>
    <body>



    <input type="button" value="press me" onclick="MyHour()">
    </body>

    </html>

    hi everyone!
    I need your help- from some reason this script doesn't work - according to firebug in firefox it's becuase i didn't define a date but as we know the arg var now=new Date();
    returns the date otomaticly, correct?
    so what is wrong with my function?

    Needs your help quickly
    Progfrog
     
    progfrog, Jan 10, 2008 IP
  2. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    getHours()
    getMinutes()
     
    MMJ, Jan 10, 2008 IP
  3. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    var d = document; 
    var b = d.body;
    function MyHour(){
    	var text;
    	if (Mhour <= 9)
    		text = 'you can still sleep';
    	else {
    		if (Mhour <= 17)
    			text = 'you should work';
    		else
    			text = 'evening time';
    	}
    	b.appendChild(d.createTextNode(text));
    }
    PHP:
    Edited.
     
    MMJ, Jan 11, 2008 IP