Answer to Question #170747 in HTML/JavaScript Web Application for Garimalla Bharath Kumar

Question #170747

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


"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 = /* Write your code here */


/* Please do not modify anything below this line */

 console.log(`${manufacturingDate.getDate()}-${manufacturingDate.getMonth() + 1}-${manufacturingDate.getFullYear()}`);

}


1
Expert's answer
2021-03-11T06:55:08-0500
"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