Skip to content

Instantly share code, notes, and snippets.

@stephenhmarsh
Created March 22, 2017 04:14
Show Gist options
  • Save stephenhmarsh/0d3d65aed5f8ca7c26dd00341ad56c28 to your computer and use it in GitHub Desktop.
Save stephenhmarsh/0d3d65aed5f8ca7c26dd00341ad56c28 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=0d3d65aed5f8ca7c26dd00341ad56c28
<!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>
// ScriptEd has a totally awesome nightclub. It's called FUNKTION.
// 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 wrote a function called yearsSinceDate to help you. (It's at the bottom of this code.)
// Example usage: 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 9.87671698798199 years old
// INSTRUCTIONS
// Declare a function called bouncer that takes three parameters for a birthday: month, day, year.
// If we call bouncer with a birthday less than 21, use conso
// HINT: remember the > and < operators for numbers!
// !!!!! Starter Code!! Don't change anything below here !!!!!
// Also, don't worry about how these work, but you can probably figure it out if you read it :)
function subtractFromToday(month, day, year) {
var someOtherDate = new Date(year, month, day);
var today = new Date();
return (today - someOtherDate);
}
function convertToYears(milliseconds) {
return milliseconds / (1000 * 60 * 60 * 24 * 365);
}
function yearsSinceDate(month, day, year){
return convertToYears(subtractFromToday(month, day, year));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment