| | |
calculate mean function!
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2008
Posts: 57
Reputation:
Solved Threads: 1
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 :-
I decide to write MeanCalculation function and standardDevationCalculation function and NUmberReader function
My NumberReader function is
Is this function correct?
I need help in writing mean function
thanks,
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)
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> Calculator</title> <script type="text/javascript" src="mean.js"></script> </head> <body> <p>This page calculates mean and standard deviation</p> </body> <script type="text/javascript"> var n=new Array(); </script> </html>
I decide to write MeanCalculation function and standardDevationCalculation function and NUmberReader function
My NumberReader function is
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function NumberReader() { var i; this.n = prompt("Enter a list of numbers separated by spaces:", "").split(" "); for(i=0;i<this.n.length;i++) { document.write("<br />["+i+"] = "+this.n[i]); } }
Is this function correct?
I need help in writing mean function
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function meanCalculation() { var i; var sum; var mean; for(int i = 0; i<this.n.length;i++) {
thanks,
•
•
•
•
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)
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> Calculator</title> <script type="text/javascript" src="mean.js"></script> </head> <body> <p>This page calculates mean and standard deviation</p> </body> <script type="text/javascript"> var n=new Array(); </script> </html>
I decide to write MeanCalculation function and standardDevationCalculation function and NUmberReader function
My NumberReader function is
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function NumberReader() { var i; this.n = prompt("Enter a list of numbers separated by spaces:", "").split(" "); for(i=0;i<this.n.length;i++) { document.write("<br />["+i+"] = "+this.n[i]); } }
Is this function correct?
I need help in writing mean function
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function meanCalculation() { var i; var sum; var mean; for(int i = 0; i<this.n.length;i++) {
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
Hope that this will help you up...
javascript Syntax (Toggle Plain Text)
<html> <head> <title>Calculator</title> <script type="text/javascript"> function numberReader() { x = []; n = prompt('Enter a number that is separated by "space" or ","',''); m = n.replace(/(\s)|(\,)/g, '').slice(); for ( var i = 0; i < m.length; i++) { x[i] = m[i]; } document.write((x[0]*1 + x[3]*1)); } </script> </head> <body> <br /> <br /> <p> This demo will convert UI value into an array and add it on the base reference. (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> <p> <script type="text/javascript"> numberReader(); </script> </p> </body> </html>
![]() |
Similar Threads
- calculatecharges function (C++)
- Function Minimisation using Simulated Annealing Algorithm (Java)
- Using Function Help (C++)
- Project Help: Growth of a Function (Java)
- Using a for loop to sum an integer n and call function add_it (C)
- loop in main function to an "if" statement (C++)
- missing function header (C++)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Dynamic ID
- Next Thread: Printing bill using javascript
Views: 1274 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxcode ajaxhelp animate api array automatically autoplay beta boarder box bug calendar captcha card cart codes column cookies createrange() css cursor date debugger decimal design developer dom download dropdown element enter error events firefox firehose flash focus form frameworks getselection google gwt html htmlform iframe image() index java javascript javascripts jawascriptruntimeerror jquery jsp listbox maps marquee masterpage menu microsoft mimic mp3 mp4 offline onmouseover parameters php player post problem programming progressbar prototype rating redirect regex safari scale scriptlets search select size sources sql starrating text textarea toggle twitter validation variables w3c web website window windowofwords windowsxp xml xspf





