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

    Creating a grading rubric array

    Hello, I'm taking a JS class and have an assignment where I need to create an array to store grades. The assignment is as follows:
    You will create the pseudo-code and Java Script program which will prompt the user for four (4) numeric grades.

    Use an array to store the grades.
    Use a looping structure to populate the array.
    Calculate the numeric average based upon the 4 equally-weighted numeric grades.
    Display each of the 4 numeric grades from the array on the screen using a looping structure.
    Display the numeric average.
    Create a function that will convert the numeric average to a letter grade average using the grading scale:
    o A = 90 to100
    o B = 80 to 89
    o C = 70 to 79
    o D = 60 to 69
    o F = 0 to 59
    The function must return the value of the letter grade average.
    Display the letter grade average.

    I have been struggling with this class a lot, as I understand the theory but fall short on the implementation. Most of the assignments I have been trying to re-purpose some of my older code to make it work, but unfortunately I just don't get arrays at all.
    I'm looking for anything to get me started or what have you, right now all that I have is this:
    <script type="text/javascript">
    // Declare variables and constants
    var SIZE = 5;		// size of array
    var grades;               // array for grades
    var average;             // average of grades
    var index;			// loop index
    var ES = "";		// empty string
    var BR = "<br />";	// HTML line break
    // Create grade array
    grades = new Array(SIZE);
    // Prompt user to enter numeric values
    for (index = 0; index < SIZE; index++) {
    	grades[index] = prompt
    ("Enter score value #" + (index + 1) +
    ":", ES);
    // Display grades
    document.write("Grades entered:" + BR + BR);
    for (index = 0; index < SIZE; index ++) {
    	document.write(grades[index] + BR);
    // Thank the user and end program
    document.write("Thank you, have a great day." + BR);
    Thank you so much for any help you can give me!
    Last edited by vinyl-junkie; Dec 3rd, 2017 at 04:44 AM. Reason: added code tags

  2. #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Thanked 602 Times in 596 Posts


    Do not use document.write in any program that modifies the screen after being loaded.
    Doing so causes the program to reload and start over when executed, losing all earlier inputs.

    Prompt is not a very good user entry mode. Anytime the user makes a mistake, they need to start all over AGAIN!
    Note, all users make mistakes at the worst possible moment in any project.

    Some questions:
    1. Why do you create an array of 5 elements when only 4 are averaged. Which one is dropped?
    OR consider changing SIZE = 4; since array start at 0 as in [0,1,2,3]. Array size is 4 entries.
    2. Where is your attempt to sum the values to form the averages? Using 4 or 5 entries?
    3. Where do you store the averages? A different array maybe?
    4. Where is your attempt to translate the numeric grade to a letter grade?
    Consider using several 'if .. then [.. else]' statements for this problem.

    BTW, welcome to the forums.
    Last edited by jmrker; Dec 3rd, 2017 at 05:28 AM.


Tags for this Thread

Posting Permissions

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