...

View Full Version : need help with making a grade converter



cari44
10-31-2006, 04:29 PM
Hi,

First of all, I'm very new to javascript but I do have knowledge of html. My boyfriend has a computer class and I told him I'd help him out as much as I can with his homework. Well, little did I know, I have no idea where to begin. I was able to complete the first question, but I'm now stuck here on the second.

So below is the question. I have no idea where to even begin. I know it may be too much to as for the whole code, but if anyone can point in a direction of where to start I'd be very thankful. Anything such as what type of code it is, where to look etc.. Thank you!

"Write a javascript funtion that converts a numerical grade to a letter grade. The write a program that continuously prompts the user for input. (The numerical grade), uses your function to convert the numerical grade to the letter grade and displays the letter grade on the screen until the user no longer wishes to continue. The user will click cancel when he doesn't want to continue.

You can assume the user will always use an integer but it may be any integer. If the user puts in an invalid numerical grade(such as a number less than 0 or greater than 100) the program should just put: Invalid Input.

Use this grading scheme:

85-100 = A
80-84 = A-
75-79 = B+
70-74 = B
65-69 = B-
60-64 = C+
55-59 = C
50-54 = D
0-49 = F

Once again, any help is appreciated! thanks

homerUK
10-31-2006, 05:21 PM
do something like:

1. prompt the user for an input



var result = prompt('Please enter the grade', ' ');


2. place the result



if (result <= 49) {
alert("Grade F");
}

if ((result >= 50) && (result <= 54)) {
alert("Grade E");
}
etc. etc.


that should do the trick! :)

VortexCortex
10-31-2006, 05:48 PM
Here you go! Hope you don't mind one-liners...


<a href="javascript:var g;while((g=prompt('Enter a numeric grade 0-100'))!=null){g=parseInt(g);if(isNaN(g)||(g<0)||(g>100))alert('Invalid Input');else{var l;if(g>=85)l='A';else if(g>=80)l='A-';else if(g>=75)l='B+';else if(g>=70)l='B';else if(g>=65)l='B-';else if(g>=60)l='C+';else if(g>=55)l='C';else if(g>=50)l='D';else l='F';alert('Grade: '+g+' = '+l+'.');}}">Click here to convert grades</a>

Philip M
10-31-2006, 06:40 PM
Here you go! Hope you don't mind one-liners...


<a href="javascript:var g;while((g=prompt('Enter a numeric grade 0-100'))!=null){g=parseInt(g);if(isNaN(g)||(g<0)||(g>100))alert('Invalid Input');else{var l;if(g>=85)l='A';else if(g>=80)l='A-';else if(g>=75)l='B+';else if(g>=70)l='B';else if(g>=65)l='B-';else if(g>=60)l='C+';else if(g>=55)l='C';else if(g>=50)l='D';else l='F';alert('Grade: '+g+' = '+l+'.');}}">Click here to convert grades</a>


The class teacher, being on the dim side, will almost certainly not realise that this "one liner" is not the student's own work. :p

cari44
11-01-2006, 04:38 PM
Thanks! His teacher didn't seem very smart... When I looked over the class notes, there was nothing about what I needed to know which was pretty confusing. But thanks!:)

Woops, what I meant to add was that his teacher doesn't seem to know very much about his topic and I'm actually pretty sure he could get away with it... or maybe not. lol



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum