Question

6.12 LAB: Grade distribution In this lab, you will write a JavaScript program that generates a...

6.12 LAB: Grade distribution

In this lab, you will write a JavaScript program that generates a bar graph of letter grades from a distributions of scores.

Implement the parseScores function (1 point)

Implement the parseScores function to take a space-separated string of scores as an argument and return an array of score strings. Each score is a number in the range [0, 100]. Ex: "45 78 98 83 86 99 90 59" → ["45","78","98","83","86","99","59"]

Hint: JavaScript's string split() function can create the array with one line of code.

Implement the buildDistributionArray function (2 points)

Implement the buildDistributionArray function to take an array of scores, built by parseScores, as an argument. A grade distribution array of length 5 is returned.

Loop through the scores array and tally up the number of A, B, C, D, and F scores using the standard scoring system (90 and above = A, 80‐89 = B, 70‐79 = C, etc.). Store these totals in a distribution array where the number of As is the first number, number of Bs is the second number, etc. Ex: ["45","78","98","83","86","99","59"] → [2, 2, 1, 0, 2]

buildDistributionArray returns [0, 0, 0, 0, 0] when the scoresArray argument is empty.

Implement the setTableContent function (7 points)

Implement the setTableContent function to take a space-separated string of scores as an argument, and produce a grade distribution graph by setting the innerHTML of the table on the page. The table has id="distributionTable".

Use a <div> for each bar. Each bar gains 10 pixels in height per grade occurrence. Use the styles from the embedded style sheet so that each bar is a different color. The CSS vertical-align property is set for <td> elements, so that the bars are aligned at the bottom of the containing cells. Below is a sample of what might be generated for the table's first row.

<tr>
   <td><div style="height:60px" class="bar0"></div></td>
   <td><div style="height:40px" class="bar1"></div></td>
   <td><div style="height:20px" class="bar2"></div></td>
   <td><div style="height:0px"  class="bar3"></div></td>
   <td><div style="height:40px" class="bar4"></div></td>
</tr>

If the input contains at least one score, then create 3 rows in the table. The first row contains divs for the bars. The second row contains letter grade labels. The third row contains the number of occurrences of each grade. Below is a sample of what the table might look like.

If the input does not contain any scores, then create only 1 cell in the table, with text content "No graph to display".

-------------------------------------------------------------------------------------------------------------------------------------------------

function parseScores(scoresString) {
   var inString = scoresString.split(" ");
return inString;
}

function buildDistributionArray(scoresArray) {
var result = [0, 0, 0, 0, 0];

   for(var i=0; i<scoresArray.length; i++) {
var s = parseInt(scoresArray[i]);
if(s >= 90) {
result[0] += 1;
} else if(s >= 80) {
result[1] += 1;
} else if(s >= 70) {
result[2] += 1;
} else if(s >= 60) {
result[3] += 1;
} else {
result[4] += 1;
}
}

return result;
}

function setTableContent(userInput) {
  
function bodyLoaded() {
// The argument passed to writeTableContent can be changed for
// testing purposes
//setTableContent("");
setTableContent("45 78 98 83 86 99 90 59");
//setTableContent("45 40 8 8 6 9 0 9");
}

function parseScores() is correct I received full credit

function buildDistributionArray() is correct I received full credit

I need help mainly with the table

Homework Answers

Answer #1

function setTableContent(userInput) {
        var scores = parseScores(userInput);

scores = scores.filter(function (el) { return el != ""; });

        var distArr = buildDistributionArray(scores);

        var table = document.getElementById('distributionTable');

        if(scores.length == 0) {
                table.innerHTML += 'No graph to display';
        } else {
                var fRow = '<tr>'
                for(var i=0; i<5; i++) {                        
                        fRow += '<td><div style="height:' + (10 * distArr[i]) + 'px" class="bar' + i + '"></div></td>';
                }
                fRow += '</tr>';
                table.innerHTML += fRow;
                
                table.innerHTML += '<tr><td>A</td><td>B</td><td>C</td><td>D</td><td>F</td></tr>';

                var lRow = '<tr>'
                for(var i=0; i<5; i++) {                        
                        lRow += '<td>' + distArr[i] + '</td>';
                }
                lRow += '</tr>';
                table.innerHTML += lRow;
        }
}

**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
IN PSUEDOCODE PSUEDOCODE PSUEDOCODE PSUEDOCODE Write a program to calculate 10 students’ average test scores and...
IN PSUEDOCODE PSUEDOCODE PSUEDOCODE PSUEDOCODE Write a program to calculate 10 students’ average test scores and the grade. (You will ask the user to input all students and their grades). You may assume the following input data: Jack Johnson 85 83 77 91 76 Lisa Aniston 80 90 95 93 48 Andy Cooper 78 81 11 90 73 Ravi Gupta 92 83 30 69 87 Bonny Blair 23 45 96 38 59 Danny Clark 60 85 45 39 67 Samantha...
In this project you implement a program such that it simulates the process of repeated attempts...
In this project you implement a program such that it simulates the process of repeated attempts to hit a target with a projectile. The goal is to shoot the projectile within a 1 foot distance from the target, since such a short miss is accepted as a hit. Your program is responsible for the following tasks. Compute the trajectory data of a projectile (such as the time, the maximum height and the distance as described by the formulas above) for...
I am making a game like Rock Paper Scissors called fire water stick where the rules...
I am making a game like Rock Paper Scissors called fire water stick where the rules are Stick beats Water by floating on top of it Water beats Fire by putting it out Fire beats Stick by burning it The TODOS are as follows: TODO 1: Declare the instance variables of the class. Instance variables are private variables that keep the state of the game. The recommended instance variables are: 1. 2. 3. 4. 5. 6. A variable, “rand” that...
USING C++ The purpose of this assignment is the use of 2-dimensional arrays, reading and writing...
USING C++ The purpose of this assignment is the use of 2-dimensional arrays, reading and writing text files, writing functions, and program planning and development. You will read a data file and store all of the input data in a two dimensional array. You will perform calculations on the data and store the results in the 2 dimensional array. You will sort the array and print the results in a report. Instructions You will read in the same input file...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
For the rest of the lab, you will make the assumption that your data is approximately...
For the rest of the lab, you will make the assumption that your data is approximately normally distributed. Use Excel to answer the following questions for the Net Sales data. Copy and paste the output below, don’t include as a separate file, make sure your x axis is labelled properly. You will have to “insert” your graphs in the appropriate places below. Please don’t upload more than one file for me to open and grade, your entire lab should be...
Do the TODOs in SongFileAccessor.java. It inherits from FileAccessor class. TODO 1: Implement the processLine method....
Do the TODOs in SongFileAccessor.java. It inherits from FileAccessor class. TODO 1: Implement the processLine method. When the text file is processed, each line of text will be passed to processLine . Each line contains 4 fields: title, album, artist, and play time. The album field is optional. Each field is separated by a comma. TODO 2: Implement the songToCSVString method. This method takes a Song object as a parameter and returns a String which is the csv representation of...
Bivariate Data & Probability After completing the calculation by hand in Q1 you can use Excel...
Bivariate Data & Probability After completing the calculation by hand in Q1 you can use Excel to check your answers before submitting. Q2 assesses your general understanding of probability and linear associations using Excel to analyse a large dataset. Question 1       Covariance and Correlation The table below shows a set of sample bivariate data. Calculate the covariance and correlation coefficient by completing the below table. Show all working. X Y (X - ) (Y - ) (X - )(Y -...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT