matthewb
04-15-2003, 04:58 PM
Hello
I've been looking for a script I can adapt (being pretty lame at javascript) to do the following task and can't find one. So I'm asking you guys; 'cos you're clever an' that :)
I have a textarea which ends up with a lot of content along the lines of:
thing one (5/5)
the other thing (3/5)
XXX (1/5)
summat else maybe (5/5)
I'm looking for a script which will extract the numbers from this text area and do the following to them on a button click (NB: there will only be numbers inside brackets - nowhere else inside the text area):
1) Add each of the individual digits together (in our example we'd get 34).
2) Subtract 'a' number (in the example I want to lose all of the second '5's so I'd minus '20').
3) Divide the total by a number (in this example the number of results - so divide by '4'*.
*in the test it's possible to skip questions so it might be handy if, instead of using a 'static number' it uses a number value equal to the number of close brackets (the reverse parentheses character).
In essence it calculates an average score from some test results. It should calculate the average score based only on the answers completed, which could in theory vary. All of the output takes the form listed above (ie. blah blah blah (X/5)).
The name of the textarea with the results is 'compileddata'.
I'd be *really* good if it could take the average score and do something along the lines of:
if averagescorevalue=1.0-1.5 message='you are a thicky'
if averagescorevalue=1.51-2.0 message='you are still pretty thick'
if averagescorevalue=2.01-2.5 message='you are average'
if averagescorevalue=2.51-5.0 message='OK, smarty-pants, go away'
...where the 'message' would be displayed in a text field (because another script will copy it from there and format it in nicely with the rest of their feedback).
I'm a bit thick, so cut and paste would be brilliant :)
Cheers in advance for any help.
Matthew
I've been looking for a script I can adapt (being pretty lame at javascript) to do the following task and can't find one. So I'm asking you guys; 'cos you're clever an' that :)
I have a textarea which ends up with a lot of content along the lines of:
thing one (5/5)
the other thing (3/5)
XXX (1/5)
summat else maybe (5/5)
I'm looking for a script which will extract the numbers from this text area and do the following to them on a button click (NB: there will only be numbers inside brackets - nowhere else inside the text area):
1) Add each of the individual digits together (in our example we'd get 34).
2) Subtract 'a' number (in the example I want to lose all of the second '5's so I'd minus '20').
3) Divide the total by a number (in this example the number of results - so divide by '4'*.
*in the test it's possible to skip questions so it might be handy if, instead of using a 'static number' it uses a number value equal to the number of close brackets (the reverse parentheses character).
In essence it calculates an average score from some test results. It should calculate the average score based only on the answers completed, which could in theory vary. All of the output takes the form listed above (ie. blah blah blah (X/5)).
The name of the textarea with the results is 'compileddata'.
I'd be *really* good if it could take the average score and do something along the lines of:
if averagescorevalue=1.0-1.5 message='you are a thicky'
if averagescorevalue=1.51-2.0 message='you are still pretty thick'
if averagescorevalue=2.01-2.5 message='you are average'
if averagescorevalue=2.51-5.0 message='OK, smarty-pants, go away'
...where the 'message' would be displayed in a text field (because another script will copy it from there and format it in nicely with the rest of their feedback).
I'm a bit thick, so cut and paste would be brilliant :)
Cheers in advance for any help.
Matthew