This JavaScript project processes and validates learner assignment submissions for a course, calculates their scores, and computes averages.
This project includes a function that takes in course information, assignment details, and learner submissions. It validates the dates and scores of the submissions, processes them to compute individual assignment scores, and calculates the average score for each learner.
- Date Validation: Ensures that the submission and due dates are in the correct
YYYY-MM-DDformat and are valid dates. - Score Processing: Calculates individual assignment scores and deducts points for late submissions.
- Future Assignment: Assignments not yet due are excluded from the results and average calculations.
- Average Calculation: Computes the average score for each learner based on their assignment scores.
- Error Handling: Provides error messages for invalid data such as incorrect date formats, invalid possiable points or mismatched course IDs.
- Clone the repository or download the
index.jsfile. - Ensure you have Node.js installed to run the JavaScript code.
-
Include your course, assignment group, and learner submissions data in the respective objects.
-
Run the script using Node.js:
node index.js
-
The results will be logged in the console.
Below is an example of valid input data for CourseInfo, AssignmentGroup, and LearnerSubmissions:
const CourseInfo = {
id: 451,
name: "Introduction to JavaScript",
};
const AssignmentGroup = {
id: 12345,
name: "Fundamentals of JavaScript",
course_id: 451,
assignments: [
{
id: 1,
name: "Declare a Variable",
due_at: "2023-01-25",
points_possible: 50,
},
{
id: 2,
name: "Write a Function",
due_at: "2023-02-27",
points_possible: 150,
},
],
};
const LearnerSubmissions = [
{
learner_id: 125,
assignment_id: 1,
submission: {
submitted_at: "2023-01-25",
score: 47,
},
},
{
learner_id: 125,
assignment_id: 2,
submission: {
submitted_at: "2023-02-12",
score: 150,
},
},
];For the above input, the output will be:
{
ID: 125,
Average: "1.000",
"Assignment 1": "0.940",
"Assignment 2": "1.000"
}
]
const LearnerSubmissions = [
{
learner_id: 125,
assignment_id: 1,
submission: {
submitted_at: "25-01-2023", // Invalid date format
score: 47,
},
},
{
learner_id: 125,
assignment_id: 2,
submission: {
submitted_at: "2023-02-12",
score: 150,
},
},
];
Warning: The date format should be YYYY-MM-DD.
Please verify and correct your Date for Declare a Variable
Error detected.
const CourseInfo = {
id: 451, // Course ID
name: "Introduction to JavaScript",
};
const AssignmentGroup = {
id: 12345,
name: "Fundamentals of JavaScript",
course_id: 999, // Mismatched course ID
assignments: [
{
id: 1,
name: "Declare a Variable",
due_at: "2023-01-25",
points_possible: 50,
},
{
id: 2,
name: "Write a Function",
due_at: "2023-02-27",
points_possible: 150,
},
],
};
const LearnerSubmissions = [
{
learner_id: 125,
assignment_id: 1,
submission: {
submitted_at: "2023-01-25",
score: 47,
},
},
{
learner_id: 125,
assignment_id: 2,
submission: {
submitted_at: "2023-02-12",
score: 150,
},
},
];
Warning: Course ID Mismatch.
Please verify and correct your Course ID for Introduction to JavaScript.
Error detected.
const AssignmentGroup = {
id: 12345,
name: "Fundamentals of JavaScript",
course_id: 451,
assignments: [
{
id: 1,
name: "Declare a Variable",
due_at: "2023-01-25",
points_possible: 0, // Invalid possible points
},
{
id: 2,
name: "Write a Function",
due_at: "2023-02-27",
points_possible: 150,
},
],
};
Warning: Invalid Possible Points.
Please verify and correct the Possible Points for Assignment Declare a Variable.
Error detected.