473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
Nov 2 '06 #1
2 1521
RamananKalirajan
608 512MB
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="javascript">
function calculateThis()
{
var suit = document.getElementById('txtBox').value;
var totSuit = parseInt(suit);
if(totSuit>4)
var lessSuit = totSuit/5;
else
var lessSuit = 0;
lessSuit = Math.floor(lessSuit);
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="Calculate the Amount" onclick="calculateThis()">
</body>
</html>[/HTML]

Regards
Ramanan Kalirajan
Mar 18 '08 #2
gits
5,390 Expert Mod 4TB
hi ...

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

Expand|Select|Wrap|Line Numbers
  1. if(totSuit>4)
  2.           var lessSuit = totSuit/5;
  3.      else
  4.            var lessSuit = 0;
there are two ways around such constructs:

Expand|Select|Wrap|Line Numbers
  1. // 1 way ... init the var with 0
  2. var lessSuit = 0;
  3.  
  4. if (totSuit>4) {
  5.     lessSuit = totSuit/5;
  6. }
  7.  
  8. // 2 way ... using the conditional operator
  9. var lessSuit = totSuit > 4 ? totSuit/5 : 0;
  10.  
kind regards
Mar 18 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

40
by: Chiwa | last post by:
Hey, Expression: Math.floor(x * 100) / 100 x= 4.1 gives 4.09, why in gods name? While other values for x don't give a problem. Thx in advance
23
by: Thomas Mlynarczyk | last post by:
I remember there is a programming language where you can initialize the random number generator, so that it can - if you want - give you the exactly same sequence of random numbers every time you...
12
by: Mal Ice | last post by:
I am creating an initial index.htm page on which I show some disclaimers and introduction information. In the head section I have Javascript which determines the screen resolution of the client....
4
by: Henke | last post by:
I wanna round an value in a javascript Down to nearest hundred. For example: 3234 = 3200 and 3890 = 3800 Always down and to hundred. I have tried Math.floor but that just round down to ten. Is...
1
by: nvphu | last post by:
I need to use the constant M_PI. So, I insert the directive # include <math.h>. However when compiled, there are errors : M_PI undeclared identifier. Second, I can not use the function...
6
by: sales | last post by:
Hello, I am trying to get my website checkout page to rotate / take turns displaying shopping comparison engine surveys rather than display them all 4 at the same time, thus overwhelming &...
7
by: bravesplace | last post by:
Hello, I am using the folling funtion to round a number to a single digit on my form: function round1(num) { return Math.round(num*1)/1 }
2
by: davidson1 | last post by:
Hai friends..for menu to use in my website..i found in one website....pl look below website.... http://www.dynamicdrive.com/dynamicindex1/omnislide/index.htm i downloaded 2 files.... ...
1
by: swethak | last post by:
hi, i have a code to disply the calendar and add events to that. It works fine.But my requirement is to i have to disply a weekly and daily calendar.Any body plz suggest that what modifications i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.