Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2002
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Letter To Number

    I need a way to convert input into a number. I have a function that doesn't work. Please help.

    Code:
    function totalPoints() {
    	var points = 0;
    	for (i=1; 8 >= i; i++) {
    		var x = document.forms[i].grade.value;
    		if ((x == "a") || (x == "A")) {
    			eval(points + 4);
    		}
    		else {
    			if ((x == "b") || (x == "B")) {
    				eval(points + 3);
    			}
    			else {
    				if ((x == "c") || (x == "C")) {
    					eval(points + 2);
    				}
    				else {
    					if ((x == "d") || (x == "D")) {
    						eval(points + 1);
    					}
    					else {
    						if ((x == "f") || (x == "F")) {
    							eval(points + 0);
    						}
    					}
    				}
    			}
    		}
    	}
    	return points;
    }

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Put a good description of your problem in the title that ppl understand your question.
    Also what kinda number do you wana make? Does it have a special order or what?

  • #3
    New to the CF scene
    Join Date
    Dec 2002
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry ... it was the second time I typed it in and was kind of frustrated that it didn't take the first time.

    It's going to be A = 4, B = 3, C = 2, D = 1, F = 0. It's for a GPA script I'm writing. I know there are some out there, but I would like to do one myself.

  • #4
    Regular Coder Skyzyx's Avatar
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think I might have something... but real quick: Are you using 8 separate forms for inputting the grades? I'd like to know, as I usually create a webpage to try it all out to make sure it works before I post anything...

    Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'll let you or someone else handle the input, but here's a better algorithm for getting the sum.
    Code:
    switch (x.toUpperCase()) {
    	case 'A': points++;
    	case 'B': points++;
    	case 'C': points++;
    	case 'D': points++;
    	case 'F': break;
    	default : alert("The grade '" + x + "' is not valid");
    	}
    Last edited by beetle; 12-17-2002 at 10:45 PM.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •