1

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.

Durendel
  • 489
  • 2
  • 12
  • https://stackoverflow.com/a/20628314/7628937 – 1sina1 Feb 20 '22 at 08:38
  • Could you please post on what are you receiving? when are you adding like this? `res.send(\`Width = ${new Fraction(height).toString()}'', Height = ${new Fraction(width).toString()}''\`);` – sina.ce Feb 20 '22 at 09:32
  • 1
    @sina.ce - That was the answer! I have no idea how I overlooked that. When I added your line, then the response was: `Width = 2 3/4' ', Height = 1 3/4' '`. So, I needed to tweak it with inches: `res.send(`Width = ${new Fraction(height).toString()}", Height = ${new Fraction(width).toString()}"`);`. And it worked: `Width = 2 3/4", Height = 1 3/4"` Thank you so much!! – Durendel Feb 20 '22 at 10:05
  • Much obliged :), could you please accept my answer? – sina.ce Feb 20 '22 at 10:10
  • There isn't any `"` in your "attempt". A quick read of the documentation about [JavaScript template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) will help you understand the meaning of the symbols in your expression. – axiac Feb 20 '22 at 14:58

1 Answers1

1

Please try this:

res.send(`Width = ${new Fraction(height).toString()}'', Height = ${new Fraction(width).toString()}''`);
sina.ce
  • 460
  • 2
  • 8