Home > Software design >  How do I add an inches (") symbol to a POST mathematical equation answer using Node JS/Express?
How do I add an inches (") symbol to a POST mathematical equation answer using Node JS/Express?

Time:02-21

What I'm Doing

I am building a picture frame calculator using NodeJS with Express & EJS.

Code

app.post("/measurements/calculate", (req,res) => {
    
    let FrameWidth = req.body.FrameWidth;
    let FrameWidthFraction = req.body.FrameWidthFraction
    let FrameHeight = req.body.FrameHeight;
    let FrameHeightFraction = req.body.FrameHeightFraction;
    let PictureWidth = req.body.PictureWidth;
    let PictureWidthFraction = req.body.PictureWidthFraction;
    let PictureHeight = req.body.PictureHeight;
    let PictureHeightFraction = req.body.PictureHeightFraction;
    let MatOverlap = req.body.MatOverlap;
    let width = (1/2)*((FrameHeight FrameHeightFraction)-(PictureHeight PictureHeightFraction) MatOverlap);
    let height = (1/2)*((FrameWidth FrameWidthFraction)-(PictureWidth PictureWidthFraction) MatOverlap);
    res.send(`Width = ${new Fraction(height).toString()}, Height = ${new Fraction(width).toString()}`);
});

Then when I do a JSON POST query via Postman with say:

{
    "FrameWidth": 16,
    "FrameWidthFraction": 0,
    "FrameHeight": 20,
    "FrameHeightFraction": 0,
    "PictureWidth": 11,
    "PictureWidthFraction": 0,
    "PictureHeight": 17,
    "PictureHeightFraction": 0,
    "MatOverlap": 0.5
}

Then the resulting correct answer/response is: Width = 2 3/4, Height = 1 3/4

The Problem

I am having trouble including the inches symbol " with the answer. In other words, I'm trying to get the answer from:

Width = 2 3/4, Height = 1 3/4

To

Width = 2 3/4", Height = 1 3/4"

I've attempted to interact with this line by adding " in different ways with no luck:

res.send(`Width = ${new Fraction(height).toString()}, Height = ${new Fraction(width).toString()}`);

I appreciate your help.

CodePudding user response:

Please try this:

res.send(`Width = ${new Fraction(height).toString()}'', Height = ${new Fraction(width).toString()}''`);
  • Related