<form id="estimateform">
<fieldset>
<legend><span>Photography</span></legend>
<input type="number" min="0" max="4" id="photoNum" />
<label for="photoNum">
<p># of photographers (1‑4)</p>
<p>$100/hr</p>
</label>
<input type="number" min="2" id="photoHrs" value="2" />
<label for="photoHrs">
<p># of hours to photograph (minimum 2)</p>
</label>
<input type="checkbox" id="makeBook" checked />
<label for="makeBook">
<p>Memory book</p>
<p>$350</p>
</label>
<input type="checkbox" id="photoRights" />
<label for="grantRights">
<p>Reproduction rights for all photos</p>
<p>$1250</p>
</label>
</fieldset>
<fieldset>
<legend><span>Travel</span></legend>
<input type="number" id="photoDist" min="0" />
<label for="photoDist">
<p>Event distance from Austin, TX</p>
<p>$2/mi per photographer</p>
</label>
</fieldset>
</form>
JavaScript
//const is a block scoped constant
//let is block scoped
//var is function scope or global "main" functon
const EMP_COST = 100; //cost of photographers per hour
const BOOK_COST = 350; //cost of memory book
const REPRO_COST = 1250; //cost of reproduction rights
const TRAVEL_COST = 2; //cost of travel per mile
function getEstimate( ) {
let totalCost = 0; //block scoped exists only in getEstimate
let photographers = document.getElementById("photoNum").value;
let hours = document.getElementById("photoHrs").value;
let distance = document.getElementById("photoDist").value;
let buyBook = document.getElementById("makeBook").checked; //returns true or false
let buyRights = document.getElementById("photoRights").checked;
//hourly rate for photographers
totalCost = photographers*hours*EMP_COST;
totalCost += photographers*distance*TRAVEL_COST;
totalCost += buyBook ? BOOK_COST : 0;
totalCost += buyRights ? REPRO_COST : 0;
return totalCost;
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.