Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const app = express();
- const morgan = require('morgan');
- app.use(morgan('dev'));
- //Debugging the Application
- app.get('/grade', (req, res) => {
- // get the mark from the query
- const { mark } = req.query;
- // do some validation
- if(!mark) {
- // mark is required
- return res
- .status(400)
- .send("Please provide a mark");
- }
- const numericMark = parseFloat(mark);
- if(Number.isNaN(numericMark)) {
- // mark must be a number
- return res
- .status(400)
- .send("Mark must be a numeric value");
- }
- if(numericMark < 0 || numericMark > 100) {
- // mark must be in range 0 to 100
- return res
- .status(400)
- .send("Mark must be in range 0 to 100");
- }
- if(numericMark >= 90) {
- return res
- .send("A");
- }
- if(numericMark > 80) {
- return res
- .send("B");
- }
- if(numericMark >= 70) {
- return res
- .send("C");
- }
- res
- .send("F");
- });
- // app.get('/', (req, res) => {
- // res.send('Welcome to root path!');
- // });
- // // Checkpoint 3 drills
- // //1
- // app.get('/sum', (req, res) => {
- // const a = Number(req.query.a);
- // const b = Number(req.query.b);
- // const sum = `The sum of a and b is
- // ${a + b}
- // `
- // res.send(sum);
- // });
- // //2
- // app.get('/hello', (req, res) => {
- // res
- // .status(204)
- // .end();
- // });
- // // Checkpoint 4
- // //Json data
- // app.get('/video', (req, res) => {
- // const video = {
- // title: 'Cats falling over',
- // description: '15 minutes of hilarious fun as cats fall over',
- // length: '15.40'
- // }
- // res.json(video);
- // });
- // app.get('/colors', (req, res) => {
- // const colors = [
- // {
- // name: 'red',
- // rgb: "FF0000"
- // },
- // {
- // name: "green",
- // rgb: "00FF00"
- // },
- // {
- // name: "blue",
- // rgb: "0000FF"
- // }
- // ];
- // res.json(colors)
- // })
- app.listen(8000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement