Question: Solve the problem for this: use strict; const port = 3000, http = require(http), httpStatus = require(http-status-codes), fs = require(fs); const sendErrorResponse = res =>

Solve the problem for this:

Solve the problem for this: "use strict"; const port = 3000, http

"use strict";

const port = 3000,

http = require("http"),

httpStatus = require("http-status-codes"),

fs = require("fs");

const sendErrorResponse = res =>

{

res.writeHead(httpStatus.NOT_FOUND, {"Content-Type": "text/html"});

res.write("

File Not Found!

");

res.end();

};

http

.createServer((req, res) => {

let url = req.url;

url=url.substring(1);

console.log(req.url);

if (url=="grade1.html") //DISPLAY FORM

{

res.writeHead(httpStatus.OK, {"Content-Type": "text/html"});

customReadFile(url, res);

}

else if (url.indexOf(".css") !== -1)

{

res.writeHead(httpStatus.OK, {"Content-Type": "text/css"});

customReadFile(url, res);

}

else if (url=="grade1.js") //PROCESS FORM

{

//READ FORM DATA

let A=[];

req.on("data",(data)=>{A.push(data);});

req.on("end",()=>

{

var content="",line="",choice="",ans="";

res.writeHead(200,{"Content-Type":"text/html"});

content=Buffer.concat(A).toString();

console.log("Content="+content);

A=content.split("&");

for(var i=0;i

{

if(A[i].search("choice") != -1)

{

var B=A[i].split("=");

choice=B[1];

}

}

for(var i=0;i

{

if(A[i].search("midterm") != -1)

{

var B=A[i].split("=");

midterm=B[1];

}

}

for(var i=0;i

{

if(A[i].search("final") != -1)

{

var B=A[i].split("=");

final=B[1];

}

}

console.log("choice="+choice+" midtermm="+midtermm +" final="+final +" ans="+ans);

if(choice=="Numercial")

{

if(choice=="Fall") ans=(2*parseFloat(mid)+parseFloat(fin))/3;

else if(choice=="Spring") ans=(parseFloat(mid)+2*parseFloat(fin))/3;

else ans=(parseFloat(mid)+parseFloat(fin))/2;

if(choice=="Numercial") res.output ({ans:`${ans}`});

res.output ( "grade1.ejs",{mid:`${mid}`, fin:`${fin}`,choice:`${choice}`,ans:`${ans}`});

}

else if (choice=="Letter")

{

if(choice=="Fall") ans=(2*parseFloat(mid)+parseFloat(fin))/3;

else if(choice=="Spring") ans=(parseFloat(mid)+2*parseFloat(fin))/3;

else ans=(parseFloat(mid)+parseFloat(fin))/2;

res.output ( "grade1.ejs",{mid:`${mid}`, fin:`${fin}`,choice:`${choice}`,ans:`${ans}`});

}

var output=

`

GRADE01 PROBLEM



`;

res.end(output);

});

}

else

{

sendErrorResponse(res);

}

})

.listen(3000);

console.log(`The server is listening on port number: ${port}`);

const customReadFile = (file_path, res) => {

if (fs.existsSync(file_path)) {

fs.readFile(file_path, (error, data) => {

if (error) {

console.log(error);

sendErrorResponse(res);

return;

}

res.write(data);

res.end();

});

} else {

sendErrorResponse(res);

}

};

In Fall: In Spring: In Summer: grade=(2*midterm+final)/3 grader(midterm+2*final)/3 grader(midterm+final)/2 GRADE PROBLEM1 1. Write a node application based on Lesson06 and Exercise04#2 such that the numerical or letter grade is computed for the following single-file application:(40 pts) GRADE01 PROBLEM Midterm: Final: Semester: Fall Answer: Numerical Letter Clear In Fall: In Spring: In Summer: grade=(2*midterm+final)/3 grader(midterm+2*final)/3 grader(midterm+final)/2 GRADE PROBLEM1 1. Write a node application based on Lesson06 and Exercise04#2 such that the numerical or letter grade is computed for the following single-file application:(40 pts) GRADE01 PROBLEM Midterm: Final: Semester: Fall Answer: Numerical Letter Clear

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!