Jump to content

Math.random


Aviway

Recommended Posts

If i use the function - "Math.random" with the "loop - for"(30 times), Can i "sum" all the result of the "Math.random" together????

  <script language="JavaScript">  <!--	var x=33;	var y=45;	var str="";	for (loop=1;loop<30;loop++ )	{tempature=Math.round(Math.random()* (y - x) + x);	str+=tempature+"\n";	}	sum=str+tempature;	alert(sum)  //-->  </script>

Link to comment
Share on other sites

TANX.and if i want to define for each time that the "if" function is true a "string"

	   var total2000 = 0;	   var total2001 = 0;	   var avg00="";	   var avg01="";	   var str="";		for (loop=1;loop<30;loop++ )		{temperature=Math.round(Math.random()* (45 - 33) + 33);		total2000 += temperature;		avg00=Math.round(total2000)/30;		}		for (loop=1;loop<30;loop++ )		{temperature=Math.round(Math.random()* (45 - 33) + 33);		total2001 += temperature;		avg01=Math.round(total2001)/30;		if (temperature>avg00)			{str+=temperature+"\n";			 }		}		alert("July 2000 AVG tempature is: "+avg00+"\n"+"July 2001 AVG tempature is: "+avg01+"\n"+str);

that the alert will be like that:day "n" = 43

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...