Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function howOld(dateString) {
- dateString = dateString.split('/');
- var today = new Date();
- var bday = new Date(parseInt(dateString[2]), parseInt(dateString[0]), parseInt(dateString[1]));
- var milliseconds = today.getTime() - bday.getTime();
- var minutes = Math.round(milliseconds / (1000 * 60));
- var hours = Math.round(milliseconds / (1000 * 60 * 60));
- var days = Math.round(milliseconds / (1000 * 60 * 60 * 24));
- var months = Math.round(milliseconds / (1000 * 60 * 60 * 24 * (365.25 / 12.0)));
- return 'Months: ' + months + '\nDays: ' + days + '\nHours: ' + hours + '\nMinutes: ' + minutes;
- }
- console.log(howOld(prompt('What is your birthday?(MM/DD/YYYY)')));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement