Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

routes1.js #84

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions routes/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,38 @@ const router = express.Router();

router.get("/check", (req, res) => {
res.send("Congratulations! Your app works! :)");
});
}); // comment

router.post("add", (req, res) => {
// Add logic here
res.send("sum can be printed here");
});

// hacktoberfest2019
router.post("/power", (req, res) => {
let param1 = req.body.param1;
let darthvader = req.body.darthvader;
let param2 = req.body.param2;

res.json({
result: Math.pow(param1, param2),
result: Math.pow(darthvader, param2),
meta: {
success: true,
message: `Calculated ${param1} raised to the power ${param2}`,
message: `Calculated ${} raised to the power ${param2}`,
code: 200
}
});
});

router.post("/factorial", (req, res) => {
const { param1 } = req.body;
const { darthvader } = req.body;

try {
let result = parseInt(param1, 10);
let result = parseInt(darthvader, 10);

if (result < 0) {
return res.json({
meta: {
success: false,
message: `${param1} is a negative number`,
message: `${darthvader} is a negative number`,
code: 400
}
});
Expand All @@ -46,10 +47,10 @@ router.post("/factorial", (req, res) => {
result,
meta: {
success: true,
message: `Calculated ${param1} factorial`,
message: `Calculated ${darthvader} factorial`,
code: 200
}
});
}); //hacktoberfest2019
} catch (err) {
res.json({
meta: {
Expand All @@ -63,14 +64,14 @@ router.post("/factorial", (req, res) => {

router.post("/ceil", (req, res) => {
try {
const { param1 } = req.body;
const { darthvader } = req.body;

let result = Math.ceil(parseFloat(param1, 10));
let result = Math.ceil(parseFloat(darthvader, 10));
res.json({
result,
meta: {
success: true,
message: `Calculated ${param1} ceil`,
message: `Calculated ${darthvader} ceil`,
code: 200
}
});
Expand Down