Answer to Question #171393 in HTML/JavaScript Web Application for manikanta

Question #171393

Manufacturing Date


Given a expiry date

expiryDate and number of months before expiry monthsBeforeExpiry of a product, write a JS program to find the manufacturing date.
Input

  • The first line of input contains a date string expiryDate
  • The second line of input contains a number monthsBeforeExpiry

Output

  • The output should be a single line containing the manufacturing date of the product


Sample Input 1

2020-01-21

8


Sample Output 1

21-5-2019


Sample Input 2

2021-11-12

2


Sample Output 2

12-9-2021




1
Expert's answer
2021-03-14T12:47:32-0400
"use strict";

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString.trim().split("\n").map((str) => str.trim());
    main();
});

function readLine() {
    return inputString[currentLine++];
}
/* Please do not modify anything above this line */

function main() {
    const expiryDate = new Date(readLine());
    const monthsBeforeExpiry = parseInt(readLine());
    
    const manufacturingDate = new Date(expiryDate.getFullYear(), expiryDate.getMonth() - monthsBeforeExpiry, expiryDate.getDate());

/* Please do not modify anything below this line */
    console.log(`${manufacturingDate.getDate()}-${manufacturingDate.getMonth() + 1}-${manufacturingDate.getFullYear()}`);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS