-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (37 loc) · 1.12 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const express = require('express');
const bodyparse = require('body-parser');
const app = express();
app.use(bodyparse.urlencoded({ extended: true }));
app.get('', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
app.post('/resl', (req, res) => {
const n1 = Number(req.body.num1);
const n2 = Number(req.body.num2);
if (req.body.res == '+') {
const result = n1 + n2;
res.send('Addition' + ' ' + '=' + ' ' + result);
}
else if (req.body.res == '-') {
const result = n1 - n2;
res.send('Subtraction' + ' ' + '=' + ' ' + result);
}
else if (req.body.res == '*') {
const result = n1 * n2;
res.send('Multiplication' + ' ' + '=' + ' ' + result);
}
else if (req.body.res == '/') {
const result = n1 / n2;
res.send('Division' + ' ' + '=' + ' ' + result);
}
else if (req.body.res == '%') {
const result = n1 % n2;
res.send('Modulus' + ' ' + '=' + ' ' + result);
}
else {
res.send('Please select any operations First!');
}
});
app.listen(3000, (res) => {
console.log('Connected at port 3000');
});