let b_length = parseFloat(query.b_length)
let height = parseFloat(query.height)
let area = (a_length + b_length) / 2 * height
-
- env.site.serve(
- env,
- 200,
+
+ let _out = []
+ _out.push(
`<!DOCTYPE html>
<html>
<head>
<h1>The area is: ${area} units<sup>2</sup></h1>
</body>
</html>
-`,
- 'calculatebutton.html.jst'
+`
)
- }
- else {
env.site.serve(
env,
200,
+ Buffer.from(_out.join('')),
+ 'calculate_button_trapezium.html.jst'
+ )
+ }
+ else {
+ let _out = []
+ _out.push(
`<!DOCTYPE html>
<html>
<head>
<h1>Error - Unable to Calculate</h1>
</body>
</html>
-`,
+`
+ )
+ env.site.serve(
+ env,
+ 200,
+ Buffer.from(_out.join('')),
'calculatebutton.html.jst'
)
}
let area = Math.PI * radius * radius
let circumference = Math.PI * radius * 2
let diameter = radius * 2
- if (radius < 0) {
- env.site.serve(
- env,
- 200,
+ if (isNaN(radius) || radius < 0) {
+ _out = []
+ _out.push(
`<!DOCTYPE html>
<html>
<head>
<title>Calculation</title>
</head>
<body class="olly">
-<h1>Error - Unable to Calculate Negative Radius</h1>
+<h1>Error - Unable to Calculate Missing or Negative Radius</h1>
</body>
</html>
`,
- 'calculatebutton.html.jst'
)
- }
- else {
env.site.serve(
env,
200,
+ Buffer.from(_out.join('')),
+ 'calculatebutton.html.jst'
+ )
+ }
+ else {
+ _out = []
+ _out.push(
`<!DOCTYPE html>
<html>
<head>
<h1>The diameter is: ${diameter} ${units}</h1>
</body>
</html>
-`,
+`
+ )
+ env.site.serve(
+ env,
+ 200,
+ Buffer.from(_out.join('')),
'calculatebutton.html.jst'
)
}
}
else {
- env.site.serve(
- env,
- 200,
+ _out = []
+ _out.push(
`<!DOCTYPE html>
<html>
<head>
<title>Calculation</title>
</head>
<body class="olly">
-<h1>Error - Unable to Calculate</h1>
+<h1>Please go <a href="/circle.html">here</a>.</h1>
</body>
</html>
-`,
+`
+ )
+ env.site.serve(
+ env,
+ 200,
+ Buffer.from(_out.join('')),
'calculatebutton.html.jst'
)
}