-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek09.js
More file actions
122 lines (102 loc) · 2.4 KB
/
week09.js
File metadata and controls
122 lines (102 loc) · 2.4 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const express = require('express');
const app = express();
app.set('port', (process.env.PORT || 8080));
app.use(express.static(__dirname + '/public'));
app.get('/', (req, res) => res.render('../public/test'));
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.get('/math', postage);
app.listen(app.get('port'), function() {
console.log('server running on port', app.get('port'))
});
function postage(req, res){
var weight = Number(req.query.wt);
var mail = req.query.mail;
var result = 0;
mail = mail.toLowerCase();
if (mail == "stamped")
result = stamped(res, weight, result);
if (mail == 'metered')
result = metered(res, weight, result);
if (mail == "envelope")
result = envelope(res, weight, result);
if (mail == 'package')
result = package(res, weight, result);
var params = {weight: weight, result: result};
console.log(result);
res.render('pages/index', params);
}
function stamped(res, weight, result){
console.log('entered stamped');
if(weight <= 1)
result = .5;
else if(weight <= 2)
result = .71;
else if(weight <= 3)
result = .92;
else if(weight <= 3.5)
result = 1.13;
else
result = envelope(res, weight, result);
console.log(result);
return result;
}
function metered(res, weight, result){
if(weight <= 1)
result = .47;
else if(weight <= 2)
result = .68;
else if(weight <= 3)
result = .89;
else if(weight <= 3.5)
result = 1.1;
else
result = envelope(res, weight, result);
return result;
}
function envelope(res, weight, result){
if(weight <= 1)
result = 1;
else if(weight <= 2)
result = 1.21;
else if(weight <= 3)
result = 1.42;
else if(weight <= 4)
result = 1.63;
else if(weight <= 5)
result = 1.84;
else if(weight <= 6)
result = 2.05;
else if(weight <= 7)
result = 2.26;
else if(weight <= 8)
result = 2.47;
else if(weight <= 9)
result = 2.68;
else if(weight <= 10)
result = 2.89;
else if(weight <= 11)
result = 3.1;
else if(weight <= 12)
result = 3.31;
else if(weight <= 13)
result = 3.52;
return result;
}
function package(res, weight, result){
if(weight <= 4)
result = 3.5;
else if(weight <= 8)
result = 3.75;
else if(weight <= 9)
result = 4.1;
else if(weight <= 10)
result = 4.45;
else if(weight <= 11)
result = 4.8;
else if(weight <= 12)
result = 5.15;
else if(weight <= 13)
result = 5.5;
return result;
}