1 Replies - 2919 Views - Last Post: 29 May 2013 - 08:31 AM

#1 lillemakken  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-May 13

Calling a function 10 times!

Posted 21 May 2013 - 06:48 AM

Hello!

This task I'm working wants me to create a function that returns a random whole number between 1 - 10, then test the function by calling it inside a loop which shall execute 10 times and output the 10 different numbers in the output window.

function returner(tall:uint) {
	
	
	var teller:Number =  1;
	tall = Math.floor((Math.random()*10) + 1);
	trace(tall);
	if (teller < 10) returner(tall); 
	teller++; 
	return;
	}
returner(0);



I have tried multiple things. As it stands above, I get the stack overflow error.

If I remove "returner(tall);" after the if-setting, I only get one random number.

I'm trying to make it execute 10 times as long as "teller" is less than 10, but that doesn't seem to work.

Help is much appreciated.

- lillemakken

Is This A Good Question/Topic? 0
  • +

Replies To: Calling a function 10 times!

#2 eddiehm  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 76
  • Joined: 09-March 10

Re: Calling a function 10 times!

Posted 29 May 2013 - 08:31 AM

Rather then a if statement you should be using a for loop.

http://www.republico...ls/flash/loops/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1