Skip to content

Instantly share code, notes, and snippets.

@alexpelan
Last active January 9, 2018 13:15
Show Gist options
  • Save alexpelan/109ba2d0cc18f23698cbe926d982870a to your computer and use it in GitHub Desktop.
Save alexpelan/109ba2d0cc18f23698cbe926d982870a to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=109ba2d0cc18f23698cbe926d982870a

Age Calculator!

Calculate the user's age from the year they were born!

Create Your Variables, & Get the Input Values

  1. Create a new variable called year.
  2. Get the value of the year input, and store it in the year variable.

Calculate the User's Age

  1. Create a new variable called age.
  2. Calculate the user's age by subtracting the year from 2017. Store the result in the age variable
  3. Append the user's age to the message div!

Finish early?

Add a name input. Update the message to say "NAME is X years old.", where NAME and X are the age and name variables.

<!DOCTYPE html>
<html>
<head>
<title>Age Calculator</title>
</head>
<body>
<p>What year were you born? <input id="year">
</p>
<button>Calculate</button>
<div id="message"></div>
</body>
</html>
{"enabledLibraries":["jquery"],"hiddenUIComponents":["console","editor.css"]}
$("button").click(function(){
// WRITE YOUR CODE HERE
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment