Skip to content

Instantly share code, notes, and snippets.

@bogoreh
Created March 12, 2021 07:13
Show Gist options
  • Save bogoreh/3916f342a7b71a32031878eabb8e8c14 to your computer and use it in GitHub Desktop.
Save bogoreh/3916f342a7b71a32031878eabb8e8c14 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Challenge: Donut Calculator</title>
</head>
<body>
<h1>Donut Calculator</h1>
<p>Winston eats 3 donuts a day. How many donuts will he eat in his lifetime?</p>
<form id="calculator-form">
<label>
Winston's final age:
<input type="number" name="age">
</label>
<button type="submit">Calculate</button>
<div id="calculator-results"></div>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
var calcDonuts = function(years) {
return years * 3 * 365;
};
$("#calculator-form").on("submit", function(event) {
event.preventDefault();
var $age = $(this).find("[name=age]");
var age = $age.val();
var donuts = calcDonuts(age);
$("#calculator-results").text("Winston ate " + donuts + " donuts");
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment