-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (29 loc) · 983 Bytes
/
index.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
const express = require('express')
const app = express()
const port = process.env.port || 3000
app.use(express.static('public'))
app.set('views', 'views')
app.set('view engine', 'ejs')
app.get('/calc', calcCost)
app.get('/', function(req, res) {res.render('Hello world!')})
app.listen(port, () => console.log('Mail app listening on port ' + port))
function calcCost(req, response) {
const weight = req.query.weight
const type = req.query.letterType
var cost = 0
switch (type){
case 'stamped':
cost = .55 + (Math.ceil(weight) * .15)
break;
case 'metered':
cost = .5 + (Math.ceil(weight) * .15)
break;
case 'flats':
cost = 1 + (Math.ceil(weight) * .15)
break;
case 'retail':
cost = 3.66 + (Math.floor(Math.ceil(weight)/4) * .73)
break;
}
response.render('results', {weight: weight, type: type, cost: cost.toFixed(2)})
}