Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. const express = require('express');
  2. const app = express();
  3. const morgan = require('morgan');
  4.  
  5. app.use(morgan('dev'));
  6.  
  7. //Debugging the Application
  8. app.get('/grade', (req, res) => {
  9. // get the mark from the query
  10. const { mark } = req.query;
  11.  
  12. // do some validation
  13. if(!mark) {
  14. // mark is required
  15. return res
  16. .status(400)
  17. .send("Please provide a mark");
  18. }
  19.  
  20. const numericMark = parseFloat(mark);
  21. if(Number.isNaN(numericMark)) {
  22. // mark must be a number
  23. return res
  24. .status(400)
  25. .send("Mark must be a numeric value");
  26. }
  27.  
  28. if(numericMark < 0 || numericMark > 100) {
  29. // mark must be in range 0 to 100
  30. return res
  31. .status(400)
  32. .send("Mark must be in range 0 to 100");
  33. }
  34.  
  35. if(numericMark >= 90) {
  36. return res
  37. .send("A");
  38. }
  39.  
  40. if(numericMark > 80) {
  41. return res
  42. .send("B");
  43. }
  44.  
  45. if(numericMark >= 70) {
  46. return res
  47. .send("C");
  48. }
  49.  
  50. res
  51. .send("F");
  52. });
  53.  
  54.  
  55. // app.get('/', (req, res) => {
  56. // res.send('Welcome to root path!');
  57. // });
  58.  
  59. // // Checkpoint 3 drills
  60. // //1
  61. // app.get('/sum', (req, res) => {
  62. // const a = Number(req.query.a);
  63. // const b = Number(req.query.b);
  64.  
  65. // const sum = `The sum of a and b is
  66. // ${a + b}
  67. // `
  68. // res.send(sum);
  69. // });
  70.  
  71. // //2
  72.  
  73. // app.get('/hello', (req, res) => {
  74. // res
  75. // .status(204)
  76. // .end();
  77. // });
  78.  
  79.  
  80. // // Checkpoint 4
  81. // //Json data
  82. // app.get('/video', (req, res) => {
  83. // const video = {
  84. // title: 'Cats falling over',
  85. // description: '15 minutes of hilarious fun as cats fall over',
  86. // length: '15.40'
  87. // }
  88. // res.json(video);
  89. // });
  90.  
  91.  
  92. // app.get('/colors', (req, res) => {
  93. // const colors = [
  94. // {
  95. // name: 'red',
  96. // rgb: "FF0000"
  97. // },
  98. // {
  99. // name: "green",
  100. // rgb: "00FF00"
  101. // },
  102. // {
  103. // name: "blue",
  104. // rgb: "0000FF"
  105. // }
  106. // ];
  107. // res.json(colors)
  108. // })
  109.  
  110.  
  111.  
  112. app.listen(8000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement