Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-23-2010, 02:29 AM   PM User | #1
johnmerlino
Regular Coder

 
Join Date: Oct 2009
Posts: 189
Thanks: 38
Thanked 3 Times in 3 Posts
johnmerlino is an unknown quantity at this point
custom object methods question

Hey all,

This script below is just me trying to apply some of my knowledge of object oriented javascript but it's not returning an array, the result I expect it to return:

Code:
<script type="text/javascript">

window.onload = function(){
	alert(Aby.randomize(Aby.age););
}

function Teen(age){
	this.age = age;
}

Aby = new Teen(19);

Teen.prototype.randomize = function(randomizeAge){
	var age = this.randomizeAge;
	var count = 0;
	var ageArray = [];
	var num;
	do {
	num = Math.floor(Math.random() * this.age);
		ageArray.push(num);
	} while count < 4;
	return ageArray
}

</script>
Thanks for any response.
johnmerlino is offline   Reply With Quote
Old 06-23-2010, 05:05 AM   PM User | #2
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
where is count being updated with the array length?

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 06-23-2010, 07:41 AM   PM User | #3
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,882
Thanks: 9
Thanked 291 Times in 287 Posts
Dormilich is on a distinguished road
this should throw an error at least. your while() syntax is incorrect.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 06-23-2010, 02:38 PM   PM User | #4
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
The variable count remains 0, thus your while() will enter in an infinite loop. You must increment it somewhere inside the loop.
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Users who have thanked Kor for this post:
johnmerlino (06-24-2010)
Old 06-24-2010, 02:56 AM   PM User | #5
johnmerlino
Regular Coder

 
Join Date: Oct 2009
Posts: 189
Thanks: 38
Thanked 3 Times in 3 Posts
johnmerlino is an unknown quantity at this point
There were two things wrong as stated. The while loop had incorrect syntax and the count++ increment. It appears sometimes firebug just doesn't work.
johnmerlino is offline   Reply With Quote
Reply

Bookmarks

Tags
array, javascript, method, object, prototype

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:56 AM.


Advertisement
Log in to turn off these ads.