Smoking Calculator

Introduction | Demonstration Calculator | Source Code

How The Smoking Calculator Works

This calculator takes the number of years you smoked, average number of cigarettes you smoked a day, and the current price for a pack of cigarettes and delivers a few figures:

  • Number of cigarettes you smoked in that period.
  • How much all those cigarettes would cost today.
  • How much the tobacco in those cigarettes weighed (based on 0.68 grams per cigarette).

The results can be pretty surprising. I smoked around 3/4 of a pack a day for 23 years. That turned out to be over 126,000 cigarettes, costing more than $37,000 and with tobacco weighing in at over 188 pounds. I smoked a grown man’s weight in tobacco.

Introduction | Demonstration Calculator | Source Code

Demonstration Calculator

Number of years you smoked:

Average number of cigarettes you smoked each day:

Average price for a pack of cigarettes in your area (in dollars)

Introduction | Demonstration Calculator | Source Code

Smoking Calculator Source Code

This calculator is licensed to you under Creative Commons Attribution 3.0. If you would like to use the source code on your site or create a derivative work from it, you must include the following HTML on the page where the calculator appears. We’re giving you this code for free with a legal license to use it. All you have to do is credit us in the manner we specify.

Required Credit HTML

INSTALLATION

Just cut and paste the Javascript code and HTML form below into your page. If you want to customize the appearance of the form, feel free. Just make sure the input name and form id/name values are not changed.



<script type="text/javascript">
function calcSmokes(){

// GET VALUES FROM FORM, SET VALUE TO ONE IF THE VALUE IN THE FORM IS NOT A NUMBER

var years = (isNaN(document.wcbubba.years.value)) ? 1 : document.wcbubba.years.value;
var smokes = (isNaN(document.wcbubba.smokes.value)) ? 1 : document.wcbubba.smokes.value;
var price = (isNaN(document.wcbubba.price.value)) ? 1 : document.wcbubba.price.value;

// DO CALCULATION OF NUMBER OF CIGARETTES SMOKED ROUNDED TO WHOLE NUMBER

var smoked = parseInt(years * 365.25 * smokes);

// CALCULATE TODAY'S VALUE OF ALL CIGS ROUNDED TO TWO DECIMAL PLACES

var expense = parseInt(((smoked/20) * price) *100) / 100;

// CALCULATE WEIGHT OF TOBACCO IN GRAMS AND POUNDS TO TWO DECIMAL PLACES

var weight = parseInt((smoked * 0.68) *100) / 100;
var pounds = parseInt(((weight/1000) * 2.204) * 100) / 100;

var expout = 'You smoked approximately ' + smoked + ' cigarettes.<br>At current prices, that would cost $' + expense + '.<br>And the weight of the tobacco in all those cigarettes was ' + pounds + ' pounds (' + weight +' grams).';

document.getElementById('totals').innerHTML = expout;
}
</script>

<form name="wcbubba" action="javascript:void();">
Number of years you smoked:<br>
<input type="text" size="5" name="years"><br><br>
Average number of cigarettes you smoked each day:<br>
<input type="text" size="5" name="smokes"><br><br>
Average price for a pack of cigarettes in your area (in dollars)<br>
<input type="text" size="5" name="price"><br><br>
<input type="submit" value="Show My Totals" onclick="calcSmokes()"></form><br>

<div id="totals"></div>

Leave a Reply