O'Reilly Forums: Chapter 2- Duncan Donut - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Chapter 2- Duncan Donut parseDonuts()

#1 User is offline   ltran 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 03-December 13

Posted 03 December 2013 - 07:17 PM

Hello All,
im working the duncan project in chapter 2. Understood everything, but not very clear about the block of code below. can anyone confirm this for me?
from my understanding is that

we are creating a new function called parseDonuts()

the parameter (donutString) is it just a variable name.. any name we create on the fly to hold whatever values from parseDonuts(document.getElementById().value;) then parseInt() is invoked to do conversion..then re-assign the value back to numDonuts ? then from there numDonut *12 to get new value for numCakeDonuts? and numGlazedDonuts??

<quote>
function parseDonuts(donutString) {
numDonuts = parseInt(donutString);
if (donutString.indexOf("dozen") != -1)
numDonuts *= 12;
return numDonuts;
}
</quote>


<quote> <script type="text/javascript">
function updateOrder() {
const TAXRATE = 0.0925;
const DONUTPRICE = 0.50;
var numCakeDonuts = parseDonuts(document.getElementById("cakedonuts").value);
var numGlazedDonuts = parseDonuts(document.getElementById("glazeddonuts").value);
if (isNaN(numCakeDonuts))
numCakeDonuts = 0;
if (isNaN(numGlazedDonuts))
numGlazedDonuts = 0;
var subTotal = (numCakeDonuts + numGlazedDonuts) * DONUTPRICE;
var tax = subTotal * TAXRATE;
var total = subTotal + tax;
document.getElementById("subtotal").value = "$" + subTotal.toFixed(2);
document.getElementById("tax").value = "$" + tax.toFixed(2);
document.getElementById("total").value = "$" + total.toFixed(2);
}

function parseDonuts(donutString) {
numDonuts = parseInt(donutString);
if (donutString.indexOf("dozen") != -1)
numDonuts *= 12;
return numDonuts;
}
</quote>
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users