Current location: Hot Scripts Forums » General Web Coding » JavaScript » Beginner Javascript problem with objects


Beginner Javascript problem with objects

Reply
  #1 (permalink)  
Old 12-06-11, 09:23 AM
Gonzo14 Gonzo14 is offline
New Member
 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Beginner Javascript problem with objects

Hi, i'm learning javascript, and a practice excerise I'm trying to do won't work for me. Any help would be great!

Code:
<html>
<head>
<script type="text/javascript">
function Clock(hour, mins, sec, ampm) {
	this.hour=hour;
	this.mins=mins;
	this.sec=sec;
	this.ampm=ampm;
	this.showTime=showTime();
}

function showTime() {
	with(this){
	document.write("In military time, the time is: " + Clock.hour + ":" + Clock.mins + ":" + Clock.sec);
}
}

</script>
</head>
<body>

<script type="text/javascript">
var hour=-1;
do{
hour=prompt("Please enter the hour");
}
while(isNaN(hour) || hour<1 || hour>12);

var mins=-1;
do{
mins=prompt("Please enter the mintues");
}
while(isNaN(mins) || mins<0 || mins>60);

var sec=-1;
do{
sec=prompt("Please enter the seconds");
}
while(isNaN(sec) || sec<0 || sec>60);


var ampm=-1;
do{
ampm=prompt("Please enter the am or pm");
if(ampm=="PM" || ampm=="Pm" || ampm=="pM" || ampm=="pm"){
    parseInt(hour);
	hour= hour +12;}
}
while(ampm != "am" && ampm != "pm");

var clock=new Clock(hour, mins, sec, ampm);
clock.showTime;

</script>
</body>
</html>
Reply With Quote
  #2 (permalink)  
Old 12-06-11, 09:25 AM
Gonzo14 Gonzo14 is offline
New Member
 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
by "wont work" i mean, when showTime() is executed it get "undefined" were the variable values should be
Reply With Quote
  #3 (permalink)  
Old 12-30-11, 01:35 AM
kshirin kshirin is offline
Newbie Coder
 
Join Date: May 2011
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
May be if you use this current time javascript will work.
__________________
Free Webmaster Resources
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript onclick events problem komrad JavaScript 1 10-31-08 06:21 AM
javascript expand list problem Miben PHP 1 10-28-08 03:15 AM
Problem intergrating ASP output to Javascript module Roy Vandersteen JavaScript 1 01-06-06 10:01 PM
Mixing some HTML into some JavaScript thatonedude JavaScript 2 12-30-05 11:04 AM
problem with javascript using FOR Synt JavaScript 1 05-30-05 06:54 AM


All times are GMT -5. The time now is 02:08 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.