dailylog 8-15-20
server.js
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/", (req, res) => {
res.sendFile(__dirname + "/catyears.html");
});
app.post("/catyears", (req, res) => {
console.log(req.body);
let { age } = req.body;
age = Number(age);
let catyears;
if (age === 1) {
catyears = 16;
} else if (age === 2) {
catyears = 25;
} else {
catyears = (age - 2) * 4 + 25;
}
res.send(`Your cat is roughly ${catyears}`);
});
app.listen(3002);
catyears.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cat Year Calculator</title>
</head>
<body>
<form action="/catyears" method="POST">
<input type="text" name="age" placeholder="human years" />
<button type="submit" name="submit">Calculate "Cat Years"</button>
</form>
<p>
Although there’s no reliable scientific way to calculate the relationship
between human and cat years, it’s generally agreed that the first two
years of a cat’s life are roughly equal to the first 25 of a human’s.
After this, each additional year is around four ‘cat years’.
<a
href="https://www.purina.co.uk/cats/key-life-stages/ageing/cats-age-in-human-years"
>[source]</a
>
</p>
</body>
</html>