944,150 Members | Top Members by Rank

Ad:
Dec 16th, 2004
0

I don't know how to start

Expand Post »
Hi everybody,

I am new to JavaScript and need help to start, please help to Write the script to calculate grades. Up to 10 scores can be entered. The raw scores are curved and grades are assigned. Click the "Load" button to work with the example scores. If the average is below 75, make it 75.

Assume the following 10 scores: 40, 46, 48, 56, 62, 64, 66, 70, 76, and 78. Enter the scores and press button Load. The average will be given as 60.5 ~61 so we have to add 14 (75-61) to every score. This is done by pressing button Curve.


Assume that the grades are assigned as follows: 90-100 = A, 80-89 = B, 70-79 = C, 60-69 = D, below 60 = F. The grade will be displayed by pressing button Grades.


Your help is much much appreciated.

Regards :cry:
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jounan is offline Offline
3 posts
since Dec 2004
Dec 16th, 2004
0

Re: I don't know how to start

I do not wish to do your homework for you but i will give you a start :}

Look at my problem i posted. that works fine for taking in a numeric value and adding it to another value. you want to create additional variables called 'total' and 'scores entered' or something like that and rather than set the value to form element like i am doing in my function, you want to add the value to total every time the fuction is called (maybe you have 2 buttons, one is enter test score, and another is grade)

so you collect all your test scores and click grade which calls a grade function that looks at total/scores enterd to give the average and converts it to a letter grade (use if statements)

that should be a good start. try something, post some code and i will help you more.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
beckerc is offline Offline
12 posts
since Nov 2004
Dec 16th, 2004
0

Re: I don't know how to start

I appreciate your help, but my knowledge to JavaScrip is "0", even i don't know how to start, I use notepad and save it as HTML. I tried it but it didn't work. below is class-average example:

import javax.swing.JOptionPane;

public class Average1 {

public static void main( String args[] )
{
int total; // sum of grades input by user
int gradeCounter; // number of grade to be entered next
int grade; // grade value
int average; // average of grades

String gradeString; // grade typed by user

// initialization phase
total = 0; // initialize total
gradeCounter = 1; // initialize loop counter

// processing phase
while ( gradeCounter <= 10 ) { // loop 10 times

// prompt for input and read grade from user
gradeString = JOptionPane.showInputDialog(
"Enter integer grade: " );

// convert gradeString to int
grade = Integer.parseInt( gradeString );

Please help me to do this, I can't even start.

Regards
Last edited by Jounan; Dec 16th, 2004 at 12:50 pm. Reason: submit before finish
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jounan is offline Offline
3 posts
since Dec 2004
Dec 16th, 2004
0

Re: I don't know how to start

That looks like java. Are you trying to do this in java or as a javascript in an html page?

I will look into a base page to post up in a bit. I am assuming you are doing this in an html page using javascript.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
beckerc is offline Offline
12 posts
since Nov 2004
Dec 18th, 2004
0

Re: I don't know how to start

Yes, I am doing html page using javascript.

regards
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jounan is offline Offline
3 posts
since Dec 2004
Dec 20th, 2004
0

Re: I don't know how to start

ok, I hope i am not too late. I did not check this over weekend.

here is a start. It has many bugs, but like i said, I want you to learn from this so you need to figure things out. I used to teach at college so I can't just give it to you.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4.  
  5. <title>quick sample for someone</title>
  6.  
  7. <script language="JavaScript">
  8. /***************************************************************
  9. * Function: isValidFloat(num)
  10. * Description: This function will check for a valid Float
  11. ****************************************************************/
  12. function isValidFloat(num)
  13. {
  14. var valid = "0123456789.";
  15. var temp;
  16. var decimalPointCount=0;
  17.  
  18. for (var i = 0; i < num.length; i++)
  19. {
  20. temp = num.substring(i, i + 1);
  21. if(temp==".")
  22. decimalPointCount++;
  23. if (decimalPointCount > 1)
  24. {
  25. return false;
  26. }
  27. if (valid.indexOf(temp) == "-1")
  28. {
  29. return false;
  30. }
  31. }
  32. return true;
  33. }
  34.  
  35.  
  36.  
  37. nTotalScores = 0;
  38. nNumberOfScores =0;
  39.  
  40. function getScores(num){
  41. nTotalScores = nTotalScores + num;
  42. nNumberOfScores = nNumberOfScores + 1;
  43.  
  44. }
  45.  
  46.  
  47.  
  48.  
  49. function getGrade( ) {
  50. var returnGrade = '';
  51.  
  52.  
  53.  
  54. if( )
  55. alert("the grade is" + )
  56. else if( )
  57. alert("The )
  58. else if( )
  59. alert("")
  60. else if( )
  61. alert("A Product Price 2 must have an Effective Date. Please select a second Effective Date.")
  62.  
  63.  
  64. else returnGrade = 'f'
  65. return returnGrade
  66. }
  67.  
  68.  
  69. /***************************************************************
  70.  
  71. * Function: trim(str)
  72.  
  73. * Description: This function will trim the spaces in a string
  74.  
  75. ****************************************************************/
  76.  
  77. function trim(str) {
  78.  
  79. //Remove leading spaces...
  80.  
  81. while (str.substring(0,1) == ' ') {
  82.  
  83. str = str.substring(1, str.length);
  84.  
  85. }
  86.  
  87.  
  88.  
  89. //Remove trailing spaces...
  90.  
  91. while (str.substring(str.length-1, str.length) == ' ') {
  92.  
  93. str = str.substring(0, str.length-1);
  94.  
  95. }
  96.  
  97.  
  98.  
  99. return str;
  100.  
  101. }
  102.  
  103.  
  104.  
  105.  
  106. </script>
  107.  
  108. <META name="GENERATOR" content="IBM WebSphere Studio">
  109. </head>
  110.  
  111. <body>
  112. <form name ="someForm">
  113. <table>
  114. <TR ><TD> enter a score and click button </td><td><td><input type="text" name ="something"> <input type="submit" onclick="Javascript:getScores(document.someForm.something);" > </td></tr>
  115. </table>
  116. </form>
  117. </body>
  118. </html>
  119.  
Reputation Points: 10
Solved Threads: 0
Newbie Poster
beckerc is offline Offline
12 posts
since Nov 2004
Dec 23rd, 2004
0

Re: I don't know how to start

Was that of any benefit? I think it gives you almost everything you need to do the problem specified. Please ask any questions. I would like to help, but i do not want to do your work for you.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
beckerc is offline Offline
12 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: The Message Snake
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: a weird Javascript error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC