Question

In: Computer Science

Using a text editor or IDE, copy the following list of names and grade scores and...

Using a text editor or IDE, copy the following list of names and grade scores and save it as a text file named scores.txt:
Name, Score
Joe Besser,70
Curly Joe DeRita,0
Larry Fine,80
Curly Howard,65
Moe Howard,100
Shemp Howard,85
Create a JavaScript program of the files that display high, low, and average scores based on input from scores.txt. Verify that the file exists and then use string functions/methods to parse the file content and add each score to an array. Display the array contents and then calculate and display the high, low, and average score. Format the average to two decimal places. Note that the program must work for any given number of scores in the file. Do not assume there will always be six scores and use Node Js as IDE.

Solutions

Expert Solution

If you have any problem with the code feel free to comment.

Program

const fs = require('fs');

//for storing student details

let studentDetails = {};

fs.readFile('scores.txt', 'utf-8', (err, data) => {

  //split data in by new line

  const rawDetails = data.split(/\r?\n/);

  for (let i = 0; i < rawDetails.length; i++) {

    //splitting the data by comma

    let ar = rawDetails[i].split(',');

    studentDetails[i] = { name: ar[0], score: parseInt(ar[1]) };

  }

  let sum = 0;

  let high = studentDetails[0].score;

  let low = studentDetails[0].score;

  for (let i = 0; i < rawDetails.length; i++) {

    //calculating sum

    sum += studentDetails[i].score;

    //finding high score

    if (high < studentDetails[i].score) high = studentDetails[i].score;

    //finding low score

    if (low > studentDetails[i].score) low = studentDetails[i].score;

  }

  //calculating avg

  const avg = sum / rawDetails.length;

  //printing the result

  console.log(`High score: ${high}`);

  console.log(`Low score: ${low}`);

  console.log(`Average score: ${avg.toFixed(2)}`);

});

Output


Related Solutions

In linux , Using a simple text editor, create a text file with the following name...
In linux , Using a simple text editor, create a text file with the following name &quot;Test&quot; and content: GNU GENERAL PUBLIC LICENSE The GNU General Public License is a free, copy left license for the GNU General Public License is intended to guarantee your freedom to GNU General Public License for most of our software; it applies … 2-Write the command to create the text file. 3-Print the file permissions. 4-Create a directory named &quot;361&quot; 5-Copy file &quot;Test&quot; to...
Use your favorite text editor or IDE to search for occurrences of setState. Where you found...
Use your favorite text editor or IDE to search for occurrences of setState. Where you found uses of setState, refactor the code to use JavaScript functions instead of classes and the useState hook instead of setState. import React from 'react' import ColorSlider from './ColorSlider' import ColorOutput from './ColorOutput' import styles from './ColorBrowser.module.css' class ColorBrowser extends React.Component { constructor(props) { super(props) this.state = { red: Math.floor(Math.random() * 256), green: Math.floor(Math.random() * 256), blue: Math.floor(Math.random() * 256) } } updateColor(e) { this.setState({...
Using a text editor, create a file english.txt containing the following words: yes no go come...
Using a text editor, create a file english.txt containing the following words: yes no go come thanks goodbye Create a second file chinese.txt contain the following words: shi bu qu lai xiexie zaijian Write a program that reads the words from english.txt so that the successive slots of a char * array english point to them. Use the %s conversion code in a fscanf call to read one word at a time. Similarly, read the words from chinese.txt so that...
Step 2: using text editor (WordPad) to create a web page with the following content (you...
Step 2: using text editor (WordPad) to create a web page with the following content (you may cut-and-paste): ----------------------------------------------------------------------------------- Just a screenshoot of the output Book-O-Rama Catalog Search Book-O-Rama Catalog Search     Choose Search Type:          Author      Title      ISBN             Enter Search Term:             ------------------------------------------------------------------------------------- Then save above document to the local directory (C:\temp) and make sure that you saved it in the plain text format (in the “Save as type” popup window, choose “Text Document...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs...
List the names of 4 Emotional Intelligence Domains with your scores - select and list one...
List the names of 4 Emotional Intelligence Domains with your scores - select and list one of the options on Pg 23 for Growing your Emotional Intelligence
This assignment includes the creation of a text document using Vi Editor and changing permissions to...
This assignment includes the creation of a text document using Vi Editor and changing permissions to access the new file. Use Vi Editor to create a text document Add data to your text file Save your text file Exit Vi Editor Display the contents of your file using the following tools: cat head tail Set file permissions as listed below User – RWX Group – RWX Other – RWX Use a GUI tool to display the new file in your...
using python #You've been sent a list of names. Unfortunately, the names #come in two different...
using python #You've been sent a list of names. Unfortunately, the names #come in two different formats: # #First Middle Last #Last, First Middle # #You want the entire list to be the same. For this problem, #we'll say you want the entire list to be Last, First Middle. # #Write a function called name_refixer. name_refixer should have two #parameters: an output filename (the first parameter) and the #input filename (the second parameter). You may assume that every #line will...
using c++. ALWAYS GRADE MY ANSWERS Write a program that reads students’ names followed by their...
using c++. ALWAYS GRADE MY ANSWERS Write a program that reads students’ names followed by their test scores. The program should output each student’s name followed by the test scores and the relevant grade. It should also find and print the highest test score and the name of the students having the highest test score. Student data should be stored in a struct variable of type studentType, which has four components: studentFName and studentLName of type string, testScore of type...
Please do the following in JAVA. Deposit and Withdrawal Files Use Notepad or another text editor...
Please do the following in JAVA. Deposit and Withdrawal Files Use Notepad or another text editor to create a text file named Deposits.txt. The file should contain the following numbers, one per line: 100.00 124.00 78.92 37.55 Next, create a text file named Withdrawals.txt. The file should contain the following numbers, one per line: 29.88 110.00 27.52 50.00 12.90 The numbers in the Deposits.txt file are the amounts of deposits that were made to a savings account during the month,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT