using math.floor?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mysticjimmie
    New Member
    • Nov 2006
    • 1

    using math.floor?

    hey guys, im stuck with this math.floor function. i know im supposed to use it for what im trying to do, but i dont know how to implement it. im supposed to subtract off 13.95 for every fifth suit. For example, if 5 suits are dropped off you will only charge for 4. For 7 suits you will charge for 6. For 12 suits you will charge for 10. Think about how to use the Math.floor function to compute the number of suits cleaned for free. Try to answer this question and that might help you. How many suits would be cleaned for free if 1000 or 1001 or 1002 suits were dropped off? its for a school project and i cant figure it out... any help would be awesome!!

    evan
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    suit calculation

    Hello Friend I give a code for your requirement this may be helpful for you. Inorder to calculate the amount I had specified the amount, you just give your desirted value for amount. post back me if you have any doubts or any assisstance.

    [HTML]<html>
    <head>
    <script language="javas cript">
    function calculateThis()
    {
    var suit = document.getEle mentById('txtBo x').value;
    var totSuit = parseInt(suit);
    if(totSuit>4)
    var lessSuit = totSuit/5;
    else
    var lessSuit = 0;
    lessSuit = Math.floor(less Suit);
    var paySuit = totSuit - lessSuit;
    var amount = paySuit * 50; //Here I have fixed the amount for a suit is 50
    alert(amount);
    }
    </script>
    </head>
    <body>
    <br/>
    Enter the total Suits : &nbsp&nbsp&nbsp &nbsp
    <input type="text" id="txtBox">
    <br/><br/>
    <input type="button" value="Calculat e the Amount" onclick="calcul ateThis()">
    </body>
    </html>[/HTML]

    Regards
    Ramanan Kalirajan
    Last edited by RamananKalirajan; Mar 18 '08, 07:19 AM. Reason: One small Mistake

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5390

      #3
      hi ...

      just to mention that the following lines will give you a 'strict' warning for a redeclaration of var lessSuit:

      [CODE=javascript]if(totSuit>4)
      var lessSuit = totSuit/5;
      else
      var lessSuit = 0;[/CODE]
      there are two ways around such constructs:

      [CODE=javascript]// 1 way ... init the var with 0
      var lessSuit = 0;

      if (totSuit>4) {
      lessSuit = totSuit/5;
      }

      // 2 way ... using the conditional operator
      var lessSuit = totSuit > 4 ? totSuit/5 : 0;
      [/CODE]
      kind regards

      Comment

      Working...