Created
March 22, 2017 04:18
-
-
Save stephenhmarsh/9668a0cd099b8efe27030491fb1060a2 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=9668a0cd099b8efe27030491fb1060a2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 the birthday of a person 21 or over, it should console.log the words "Welcome to Funktion." | |
// If we give bouncer the birthday of someone under 21, it should console.log the words "Sorry, not old enough" | |
// HINT: remember the > and < operators for numbers! | |
// HINT: you will need if and else statements | |
// Start your code here! | |
// !!!!! 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