JavaScript LetterGrade function -
i want write function using conditionals, determines letter grade numerical grade, passed in parameter. have correctly written in python, not sure javascript.
in js, keeps returning "you made b", "you made a(n) c", ... , "you made a(n) f", no matter number place function.
function lettergrade(grade) { if (100>=grade && grade >= 90) { alert('you made a(n) a.');} if (80 <= grade && grade< 90) { alert('you made a(n) b.');} if (70<= grade && grade < 80) { alert('you made a(n) c.');} if (60<= grade && grade < 70); { alert('you made a(n) d.');} if (0<= grade && grade < 60) { alert('you made a(n) f.');} } }
how this:
function lettergrade(grade) { // singledigitgrade integer, 1-10 var singledigitgrade = math.floor(grade / 10); if (singledigitgrade === 9 || singledigitgrade === 10) { alert('you made a(n) a.'); } else if (singledigitgrade === 8) { alert('you made a(n) b.'); } else if ( singledigitgrade === 7) { alert('you made a(n) c.'); } else if (singledigitgrade === 6) { alert('you made a(n) d.'); } else { alert('you made a(n) f.'); } }
Comments
Post a Comment