Chocolate Math - ITS UP 2 U - Information

This is a fun math trick that works only for the year 2001. Here's an example PHP code that implements it:

<!DOCTYPE html>
	<title>Chocolate Math</title>
	<h1>Chocolate Math</h1>
	<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
		<label for="chocolate">Number of times per week you want to have chocolate:</label>
		<input type="number" id="chocolate" name="chocolate" min="1" max="9"><br><br>
		<input type="submit" value="Calculate">
			$chocolate = $_POST["chocolate"];

			$result = (($chocolate * 2) + 5) * 50;
			if (date("md") >= "0422") {
				$result += 1751;
			} else {
				$result += 1750;
			$result -= $_POST["birth_year"];

			$original_number = $chocolate;
			$age = substr($result, -2);

			echo "<p>Your original number was: " . $original_number . "</p>";
			echo "<p>Your age is: " . $age . "</p>";
			echo "<p>The number you calculated is: " . $result . "</p>";

This code creates a form that asks the user to input the number of times per week they want to have chocolate and their birth year. When the user submits the form, the values are passed to the server using the POST method. The PHP code then calculates the result using the steps in the Chocolate Math trick and displays the original number, the age, and the calculated number.

Note that this is just an example and you should customize it to fit your specific needs. Also, remember that this trick only works for the year 2001, so you might want to update the code to reflect that if you plan to use it in a different year.

Click to listen highlighted text!