diff --git a/README.md b/README.md index f229958..250d535 100644 --- a/README.md +++ b/README.md @@ -1,98 +1,22 @@ Assignment 2 - Short Stack: Basic Two-tier Web Application using HTML/CSS/JS and Node.js -=== - -Due: September 8th, by 11:59 AM. - -This assignment aims to introduce you to creating a prototype two-tiered web application. -Your application will include the use of HTML, CSS, JavaScript, and Node.js functionality, with active communication between the client and the server over the life of a user session. - -Baseline Requirements ---- - -There is a large range of application areas and possibilities that meet these baseline requirements. -Try to make your application do something useful! A todo list, storing / retrieving high scores for a very simple game... have a little fun with it. - -Your application is required to implement the following functionalities: - -- a `Server` which not only serves files, but also maintains a tabular dataset with 3 or more fields related to your application -- a `Results` functionality which shows the entire dataset residing in the server's memory -- a `Form/Entry` functionality which allows a user to add, modify, or delete (complete at least two) data items residing in the server's memory -- a `Server Logic` which, upon receiving new or modified "incoming" data, includes and uses a function that adds at least one additional derived field to this incoming data before integrating it with the existing dataset -- the `Derived field` for a new row of data must be computed based on fields already existing in the row. -For example, a `todo` dataset with `task`, `priority`, and `creation_date` may generate a new field `deadline` by looking at `creation_date` and `priority` - -Your application is required to demonstrate the use of the following concepts: - -HTML: -- One or more [HTML Forms](https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms), with any combination of form tags appropriate for the user input portion of the application -- A results page displaying all data currently available on the server. You will most likely use a `` tag for this, but `
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Class:
Assignment1 Score:
Assignment2 Score:
Project Score:
Exam Score:
+ + + +
+ +

diff --git a/server.improved.js b/server.improved.js index 26673fc..fe49959 100644 --- a/server.improved.js +++ b/server.improved.js @@ -7,11 +7,10 @@ const http = require( 'http' ), port = 3000 const appdata = [ - { 'model': 'toyota', 'year': 1999, 'mpg': 23 }, - { 'model': 'honda', 'year': 2004, 'mpg': 30 }, - { 'model': 'ford', 'year': 1987, 'mpg': 14} ] - + // { 'studentName': 'Roopsa', 'a1score': 90, 'a2score': 90, 'Project Score': 91, 'Exam Score': 'A'}, + // { 'studentName': 'Hota', 'a1score': 82, 'a2score': 82, 'Project Score': 81, 'Exam Score': 'B'}, + // { 'studentName': 'Sahana', 'a1score': 75, 'a2score': 75, 'Project Score':751, 'Exam Score': 'C'} const server = http.createServer( function( request,response ) { if( request.method === 'GET' ) { handleGet( request, response ) @@ -35,15 +34,28 @@ const handlePost = function( request, response ) { request.on( 'data', function( data ) { dataString += data + console.log("-----------") + console.log(dataString) }) request.on( 'end', function() { - console.log( JSON.parse( dataString ) ) + if(request.url === "/submit"){ + //console.log( JSON.parse( dataString ) ) + + let newStudent = JSON.parse(dataString) + newStudent.finalScore = finalGrade(newStudent.a1score, newStudent.a2score, newStudent.projectSc, newStudent.examScore) + + appdata.push(newStudent) - // ... do something with the data here!!! + } else if (request.url === '/delete'){ + let i = JSON.parse( dataString ).index + appdata.splice( i, 1 ) + //console.log(appdata) + } + response.writeHead( 200, "OK", {'Content-Type': 'text/plain' }) - response.end() + response.end(JSON.stringify(appdata)) }) } @@ -69,4 +81,29 @@ const sendFile = function( response, filename ) { }) } + +function finalGrade(a1,a2,project,exam){ + console.log(a1,a2,project,exam) + let score =0; + console.log(((parseInt(a1) + parseInt(a2))/2)* 0.55,((project) * 0.35),((exam)*0.1)) + score = ((parseInt(a1) + parseInt(a2))/2)* 0.55 + (parseInt(project)) * 0.35 + (parseInt(exam))*0.1; + //score = (+a1 + +a2)*0.55 + +project*0.35 + +exam*0.1 + let grade ="" + + if(score > 90.0 ){ + grade = "A" + console.log(score); + } + else if(score > 80.0){ + grade = "B" + } + else if(score > 70.0 ){ + grade = "C" + } + else{ + grade = "NR" + } + return grade; +} + server.listen( process.env.PORT || port )