gpa problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: gpa problem

  1. #1
    Join Date
    Nov 2004
    Location
    New Mexico
    Posts
    1

    gpa problem

    I have this gpa program written but I can not get it to work, and I don't know what is wrong. Can someone please help.

    <HTML>
    <HEAD>
    <Title> Rachelle Ahlness </Title>

    <Script Language = "Javascript">
    var input1 = window.prompt( "Please Enter your average", "0" );

    var value1 = parseFloat( input1 );



    function qualitypoints()
    {
    if ( value1 >= 100 )
    qualitypoints = 4;
    else
    if ( 80 <= value1 >= 90 )
    quality points = 3;
    else
    if (70 <= value1 >= 80 )
    quality points = 2;
    else
    if (60 <= value1 >= 70 )
    quality points = 1;
    else
    if (value1 <= 59)
    quality points = 0;
    }

    document.writeln ( "You have " + qualitypoints + " quality points and a " + lettergrade + " letter grade" );

    </SCRIPT>
    </HEAD>
    <BODY>
    <p>Click refresh (or reload) to run the script again</p>
    </BODY>
    </HTML>

  2. #2
    Join Date
    Nov 2004
    Location
    Minnesota
    Posts
    99
    This worked for me:


    Code:
    <HTML>
    <HEAD>
    <Title> Rachelle Ahlness </Title>
    
    <SCRIPT language = "Javascript">
    function qualitypoints(v)
    {
    	if ( v >= 100 )
    	{
    		return 4;
    	}
    	else if ( 80 <= v || v >= 90 )
    	{
    		return 3;
    	}
    	else if (70 <= v || v >= 80 )
    	{
    		return 2;
    	}
    	else if (60 <= v || v >= 70 )
    	{
    		return 1;
    	}
    	else if (v <= 59)
    	{
    		return 0;
    	}
    }
    
    
    var input1 = window.prompt( "Please Enter your average", "0" );
    
    var value1 = parseFloat( input1 );
    
    var qp = qualitypoints(value1);
    
    var grade = "F";
    
    switch(qp) {
    	case 1: grade = "D"; break;
    	case 2: grade = "C"; break;
    	case 3: grade = "B"; break;
    	case 4: grade = "A"; break;
    	default: grade = "F";
    }
    
    document.writeln ( "You have " + qp + " quality points and a grade of " + grade);
    
    </SCRIPT>
    </HEAD>
    <BODY>
    <p>Click refresh (or reload) to run the script again</p>
    </BODY>
    </HTML>

  3. #3
    Join Date
    Nov 2004
    Location
    Minnesota
    Posts
    99
    actually, seems like qualitypoints function can be simplified:


    Code:
    function qualitypoints(v)
    {
    	if ( v < 60 )
    	{
    		return 0;
    	}
    	else if ( v < 70 )
    	{
    		return 1;
    	}
    	else if (v < 80 )
    	{
    		return 2;
    	}
    	else if (v < 90 )
    	{
    		return 3;
    	}
    	else
    	{
    		return 4;
    	}
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center