Sunday, 15 May 2011

average of five valuesin javascript -



average of five valuesin javascript -

i work charter school , i'm learning way around javascript. i've got code written person formerly filled position , seems me should work, doesn't.

this have in custom html page in sis:

ged status: <script language="javascript">gedcheck('~(elc_tspp_ged_read_score)','~ (elc_tspp_ged_wri_score)','~(elc_tspp_math_ged_score)','~(elc_science_state_exam_score)','~(soc_sci_state_exam_score)')</script>

that seems retrieving values various db fields correctly, javascript routine evaluating each value ensure it's @ to the lowest degree 410. that's far goes...

here's javascript routine code:

function gedcheck(read,wri,math,sci,soc) { if( read < 0 && read > 1000 ) read = 0; if( wri < 0 && wri > 1000 ) wri = 0; if( math < 0 && math > 1000 ) math = 0; if( sci < 0 && read > 1000 ) read = 0; if( soc < 0 && soc > 1000 ) soc = 0; if ( (read >= 410) && (wri >= 410) && (math >= 410) && (sci >= 410) && (soc >= 410) ) { if( read+wri+math+sci+soc >= 2250 ) document.write( "passed" ) } else document.write( "not passed" ) }

it supposed checking every score in ged tests @ to the lowest degree 410, , sum of scores should @ to the lowest degree 2250. however, it's not getting far lastly part. it's returning "passed" if scores on 410.

i tried it, also, doesn't work.

function gedcheck(read,wri,math,sci,soc) { if( read < 0 && read > 1000 ) read = 0; if( wri < 0 && wri > 1000 ) wri = 0; if( math < 0 && math > 1000 ) math = 0; if( sci < 0 && read > 1000 ) read = 0; if( soc < 0 && soc > 1000 ) soc = 0; if ( (read >= 410) && (wri >= 410) && (math >= 410) && (sci >= 410) && (soc >= 410) ) { if( read+wri+math+sci+soc/5 >= 450 ) document.write( "passed" ) } else document.write( "not passed" ) }

would please help me work out either averages 5 numbers , returns "passed" if average 450, or adds 5 numbers , returns "passed" if total sum 2250 or greater?

to average, you'll want this:

(((read + wri + math + sci + soc) / 5) > 450)

the parenthesis around add-on ensures split sum of scores 5. way have now, dividing soc score 5.

edit (rewriting entire method):

function gedcheck(read, wri, math, sci, soc) { // said before, these should ors // if score less 0, or greater 1000 if( read < 0 || read > 1000 ) { read = 0; } if( wri < 0 || wri > 1000 ) { // prefer set braces around if/else statements absolute clarity wri = 0; } if( math < 0 || math > 1000 ) { math = 0; } if( sci < 0 || read > 1000 ) { read = 0; } if( soc < 0 || soc > 1000 ) { soc = 0; } if ( read >= 410 && // doing pass pupil wri >= 410 && // if of conditions met. math >= 410 && sci >= 410 && soc >= 410 && ( (read + wri + math + sci + soc) >= 2250 || // separated more clarity ((read + wri + math + sci + soc) / 5) > 450) ) { // either scores total on 2250 // or average of 5 on 450 pass document.write( "passed" ) } else document.write( "not passed" ) }

javascript average

No comments:

Post a Comment