I will prompt the user to enter the years he lived then it should return the seconds he lived.
The code:
let use = prompt("Enter number of years u lived: ");
let u = parseInt(use)
let time = new Date()
let compute = time.getFullYear() - u
console.log(compute.getSeconds()+time.getFullYear());
But I get an error that says ‘Uncaught TypeError: compute.getSeconds is not a function’
>Solution :
Assuming an approximation is fine (because you’re not asking for a birth date anyway), it might be the easiest to just multiply the number by the number of seconds per year.
const seconds = years * 60 * 60 * 24 * 365;
This is not exact because it’s not accounting for leap day and leap second rules.