Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. //Variables
  2. var now = new Date();
  3. var totalDays = '';
  4. var totalMonths = '';
  5. var totalWeeks;
  6. var birthDate = new Date(document.getElementById('selYear').value, document.getElementById('selMonth').value, document.getElementById('selDay').value);
  7. var output = '';
  8.  
  9. //Total Days Old
  10. var totalDays = Math.floor((now - birthDate) / 86400000);
  11.  
  12. //Total Weeks Old
  13. totalWeeks = totalDays / 7;
  14. totalWeeks = Math.round(totalWeeks);
  15.  
  16. //Total Months Old
  17. totalMonths = totalDays / 30;
  18.  
  19.  
  20.  
  21. //Total Years
  22. var totalYears = document.getElementById('selYear').value - now.getFullYear();
  23. totalYears = Math.abs(totalYears);
  24.  
  25.  
  26.  
  27.  
  28. //Outputs
  29. output += 'You are ' + totalDays + ' days old';
  30. output += '<br />You are ' + totalWeeks + ' weeks old';
  31. output += '<br />You are ' + totalMonths + ' months old';
  32. output += '<br />You are ' + totalYears + ' Years old';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement