calculate mean function!

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Mar 2008
Posts: 57
Reputation: complexcodes is an unknown quantity at this point 
Solved Threads: 1
complexcodes complexcodes is offline Offline
Junior Poster in Training

calculate mean function!

 
0
  #1
Nov 20th, 2008
Hello,

I am supposed to write a program that prompts user to enter the numbers separated by space and when user click "ok" button, it should display the numbers entered with its mean, and standard deviation and the window should ask if user wants to enter numbers again if yes then it should display the new numbers entered, with its mean and standard deviation.

I created an external javascript file and embedded inside the strict XHTML file
here is what I got :-
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <title> Calculator</title>
  7. <script type="text/javascript" src="mean.js"></script>
  8. </head>
  9.  
  10. <body>
  11. <p>This page calculates mean and standard deviation</p>
  12. </body>
  13. <script type="text/javascript">
  14. var n=new Array();
  15. </script>
  16. </html>

I decide to write MeanCalculation function and standardDevationCalculation function and NUmberReader function

My NumberReader function is
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function NumberReader()
  2. {
  3. var i;
  4. this.n = prompt("Enter a list of numbers separated by spaces:", "").split(" ");
  5. for(i=0;i<this.n.length;i++)
  6. {
  7. document.write("<br />["+i+"] = "+this.n[i]);
  8. }
  9. }

Is this function correct?
I need help in writing mean function
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function meanCalculation()
  2. {
  3. var i;
  4. var sum;
  5. var mean;
  6. for(int i = 0; i<this.n.length;i++)
  7. {

thanks,
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 24
Reputation: sasankasekhar is an unknown quantity at this point 
Solved Threads: 3
sasankasekhar's Avatar
sasankasekhar sasankasekhar is offline Offline
Newbie Poster

Re: calculate mean function!

 
0
  #2
Nov 21st, 2008
Originally Posted by complexcodes View Post
Hello,

I am supposed to write a program that prompts user to enter the numbers separated by space and when user click "ok" button, it should display the numbers entered with its mean, and standard deviation and the window should ask if user wants to enter numbers again if yes then it should display the new numbers entered, with its mean and standard deviation.

I created an external javascript file and embedded inside the strict XHTML file
here is what I got :-
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <title> Calculator</title>
  7. <script type="text/javascript" src="mean.js"></script>
  8. </head>
  9.  
  10. <body>
  11. <p>This page calculates mean and standard deviation</p>
  12. </body>
  13. <script type="text/javascript">
  14. var n=new Array();
  15. </script>
  16. </html>

I decide to write MeanCalculation function and standardDevationCalculation function and NUmberReader function

My NumberReader function is
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function NumberReader()
  2. {
  3. var i;
  4. this.n = prompt("Enter a list of numbers separated by spaces:", "").split(" ");
  5. for(i=0;i<this.n.length;i++)
  6. {
  7. document.write("<br />["+i+"] = "+this.n[i]);
  8. }
  9. }

Is this function correct?
I need help in writing mean function
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function meanCalculation()
  2. {
  3. var i;
  4. var sum;
  5. var mean;
  6. for(int i = 0; i<this.n.length;i++)
  7. {

thanks,


First thing, please remove keyword this. There is no need to use this.n ....
Rest is fine and I hope you will be able to solve it yourself. Still if you could not develop the function ... please provide the formulae for the mean and standard deviation.

Regards
Last edited by sasankasekhar; Nov 21st, 2008 at 6:38 am.
IF SOMEONE FEELS THAT THEY HAD NEVER MADE A MISTAKE IN THEIR LIFE, THEN  IT MEANS THEY HAD NEVER TRIED A NEW THING IN THEIR LIFE
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 57
Reputation: complexcodes is an unknown quantity at this point 
Solved Threads: 1
complexcodes complexcodes is offline Offline
Junior Poster in Training

Re: calculate mean function!

 
0
  #3
Nov 21st, 2008
dude, javascript requires "this" to access instance variable. Please if you are not sure about anything dont try to help other people. You will just mess up their thinking. thanks,
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: calculate mean function!

 
0
  #4
Nov 23rd, 2008
Hope that this will help you up...

  1. <html>
  2. <head>
  3. <title>Calculator</title>
  4.  
  5. <script type="text/javascript">
  6. function numberReader()
  7. { x = [];
  8. n = prompt('Enter a number that is separated by "space" or ","','');
  9. m = n.replace(/(\s)|(\,)/g, '').slice();
  10. for ( var i = 0; i < m.length; i++) {
  11. x[i] = m[i]; }
  12. document.write((x[0]*1 + x[3]*1));
  13. }
  14. </script>
  15. </head>
  16. <body>
  17. <br />
  18. <br />
  19. <p> This demo will convert UI value into an array and add it on the base reference.
  20. (eg. Assuming that the array x[0] has a value of 1 and x[3] has a value of 4, then the output result wil be 5. It will return NaN value if the ref is out of range! Hope it clears you up. Note that it should be separated by "space" or "," Enjoy...</p>
  21. <p> <script type="text/javascript">
  22.  
  23. numberReader();
  24. </script> </p>
  25. </body>
  26. </html>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC