Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fix the problem please: use strict; const port = 3000, http = require(http), httpStatus = require(http-status-codes), fs = require(fs); const sendErrorResponse = res => {

image text in transcribed

Fix the problem please:

"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="",num="",ans="";

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

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

console.log("Content="+content);//Content=num=100&choice=Increment

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("num") != -1)

{

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

num=B[1];

}

}

console.log("choice="+choice+" num="+num);

if(choice=="") ans=parseInt(num)+1;

else if(choice=="") ans=parseInt(num)-1;

else if(choice=="Clear") ans=num="";

console.log("choice="+choice+" num="+num +" 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 grade=(midterm+2*final)/3 grade=(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 grade=(midterm+2*final)/3 grade=(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions