Skip to content

Instantly share code, notes, and snippets.

@stephenhmarsh
Created March 22, 2017 04:03
Show Gist options
  • Save stephenhmarsh/80df4a72f23c94371e96c68322650f99 to your computer and use it in GitHub Desktop.
Save stephenhmarsh/80df4a72f23c94371e96c68322650f99 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=80df4a72f23c94371e96c68322650f99
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<p>You can close the HTML, CSS, and Output panels. You will not need them since we will be working in the browser's console! :)</p>
<p>All you need is the Javascript panel!</p>
</body>
</html>
// INSTRUCTIONS
// ScriptEd has a totally awesome nightclub. It's called FUNKTION but don't worry about that.
// Unfortunately we spent all our money on lights and speakers and cannot afford a bouncer.
// Your job is to write a function to replace our bouncer with Javascript.
// I've written some functions to get you started:
// This one gives the difference (in milliseconds), between today and another day:
function subtractFromToday(month, day, year) {
var someOtherDate = new Date(year, month, day);
var today = new Date();
return (today - someOtherDate);
}
// This one converts milliseconds to years.
function convertToYears(milliseconds) {
return milliseconds / (1000 * 60 * 60 * 24 * 365);
}
// This one just combines the first two functions to give us years since a date.
function yearsSinceDate(month, day, year){
return convertToYears(subtractFromToday(month, day, year));
}
// Example: My cat's birthday is 4/9/2007. How old is she?
var missyAge = yearsSinceDate(4, 9, 2007);
console.log("Missy is " + missyAge + " years old");
// Missy is Missy is 9.87671698798199 years old
// HINT: remember the > and < operators for numbers!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment