943,712 Members | Top Members by Rank

Ad:
Nov 20th, 2008
0

calculate mean function!

Expand 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,
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
complexcodes is offline Offline
57 posts
since Mar 2008
Nov 21st, 2008
0

Re: calculate mean function!

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.
Reputation Points: 10
Solved Threads: 3
Newbie Poster
sasankasekhar is offline Offline
24 posts
since Jan 2007
Nov 21st, 2008
0

Re: calculate mean function!

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,
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
complexcodes is offline Offline
57 posts
since Mar 2008
Nov 23rd, 2008
0

Re: calculate mean function!

Hope that this will help you up...

javascript Syntax (Toggle Plain Text)
  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>
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Adding Array To Another Array
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Printing bill using javascript





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC