Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

javascript parameters returning float

  • 09-01-2005 07:05PM
    #1
    Registered Users, Registered Users 2 Posts: 884 ✭✭✭


    Can anyone find anything wrong with this ??
    function gpv(gpvval)
    	{
    		alert ("this is gpvval ... " + gpvval + "")
    		if (gpvval > 100)
    		{
    		gpvval = 'N/A';
    		}
    		if (gpvval <= 100 && gpvval >= 80)
    		{
    		gpvval = parseFloat(4.0);
    		}
    		if (gpvval <= 79 && gpvval >= 70)
    		{
    		gpvval = '3.5';
    		}
    		if (gpvval <= 69 && gpvval >= 60)
    		{
    		gpvval = 3.0;
    		}
    		if (gpvval <= 59 && gpvval >= 55)
    		{
    		gpvval = 2.5;
    		}
    		if (gpvval <= 54 && gpvval >= 50)
    		{
    		gpvval = 2.0;
    		}
    		if (gpvval <= 49 && gpvval >= 40)
    		{
    		gpvval = 1.5;
    		}
    		if (gpvval <= 39 && gpvval >= 35)
    		{
    		gpvval = 1.0;
    		}
    		if (gpvval <= 38 && gpvval >= 0)
    		{
    		gpvval = 0;
    		}
    		return gpvval;
    		}
    

    Anything above 100 works but everthing else is just 0 ??

    Any ideas ??


Comments

  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    after using the if for your first statement, use else if's


  • Registered Users, Registered Users 2 Posts: 884 ✭✭✭Cork Skate


    Ph3n0m wrote:
    after using the if for your first statement, use else if's

    Nah ... tried that ... doesn't work !!

    I am thinking that it is trying to change gpvval to a float that is doing it.
    if i change all the other values to 'L/N' or 'Ted' or whatever it works fine ... so it must be the format.

    gpvval comes from the main code parseFloat(document.form.textfield.value) so i would have thought there'd be no problem when it was pass into the function but obviously there is ... even when i enter a float i.e. 85.21 it goes straight to 0 ..... i need to be able to pass a float back down to when the function is called.

    Anyone know how to do this ??


  • Registered Users, Registered Users 2 Posts: 884 ✭✭✭Cork Skate


    function gpv(gpvval) {
    		var gpa = 0;
    		if (gpvval > 100) {
    			gpa = 'N/A';
    		} else if (gpvval >= 80) {
    			gpa = '4.0';
    		} else if (gpvval >= 70) {
    			gpa = '3.5';
    		} else if (gpvval >= 60) {
    			gpa = '3.0';
    		} else if (gpvval >= 55) 	{
    			gpa = '2.5';
    		} else if (gpvval >= 50) {
    			gpa = '2.0';
    		} else if (gpvval >= 40) {
    			gpa = '1.5';
    		} else if (gpvval >= 35) {
    			gpa = '1.0';
    		} else if (gpvval >= 0) {
    			gpa = '0';
    		}
    		return gpa;
    	}
    

    This is the one that works .... i dont know what else i did but its all good now !!


Advertisement