Need: Javascript to solve for X (proportionality)

P

Paul J. Dudley

I need a javascript to solve for X as in the following:

120.85 X
----- = ---
16 24

24 x 120.85 / 16 = X

X = 181.28

Does anyone have such ... or anything like it that I might
play with to do the same ?

= Paul =
 
E

Evertjan.

Paul J. Dudley wrote on 23 aug 2007 in comp.lang.javascript:
I need a javascript to solve for X as in the following:

120.85 X
----- = ---
16 24

24 x 120.85 / 16 = X

X = 181.28

Does anyone have such ... or anything like it that I might
play with to do the same ?

Why would you "need" that?
A school assignment?
What code dit you make sofar?
 
T

Thomas 'PointedEars' Lahn

Paul said:
I need a javascript to solve for X as in the following:

120.85 X
----- = ---
16 24

24 x 120.85 / 16 = X

X = 181.28

Does anyone have such ... or anything like it that I might
play with to do the same ?

Wrong newsgroup, try alt.school.homework-help.


PointedEars
 
P

Paul J. Dudley

Paul J. Dudley wrote on 23 aug 2007 in comp.lang.javascript:


Why would you "need" that?
A school assignment?
What code dit you make sofar?

I have no code so far. I am JS illiterate. I do a little hacking of
existing scripts when needed, but have never created from scratch.
I used to get JSs from a JS site, but nothing I can use for my purpose.

There are 5 of us who work for the same company and it would give us
a rough idea of how much take home pay we can expect given a certain
amount of hours worked. We all make the same low wages, so we can compare
against hrs worked vs amount paid previously. The numbers used were just
for analogy sake.

= Paul =
 
E

Evertjan.

Paul J. Dudley wrote on 23 aug 2007 in comp.lang.javascript:
I have no code so far. I am JS illiterate. I do a little hacking of
existing scripts when needed, but have never created from scratch.
I used to get JSs from a JS site, but nothing I can use for my
purpose.

There are 5 of us who work for the same company and it would give us
a rough idea of how much take home pay we can expect given a certain
amount of hours worked. We all make the same low wages, so we can
compare against hrs worked vs amount paid previously. The numbers
used were just for analogy sake.

Ask yourself:
What is the input format?
What are constants, what are input dependent variables?
What is the output format?
Then look at the Javascript FAQ of this NG and start learing.

Q not answered yet:
 
P

Paul J. Dudley

Paul J. Dudley wrote on 23 aug 2007 in comp.lang.javascript:
:
etc
:

Q not answered yet:

There are 5 of us who work for the same company and it would give us
a rough idea of how much take home pay we can expect given a certain
amount of hours worked. We all make the same low wages, so we can compare
against hrs worked vs amount paid previously. The numbers used were just
for analogy sake.

As for the FAQ, I believe I inadvertently deleted it ( without knowing ).

= Paul =
 
T

Thomas 'PointedEars' Lahn

Paul said:
I have no code so far. I am JS illiterate. I do a little hacking of
existing scripts when needed, but have never created from scratch.
I used to get JSs from a JS site, but nothing I can use for my purpose.

It would seem that your problem is not JS, but a lack of programming skills.
Here you are:

window.alert("X = " + 120.85 * 24 / 16);

Beware of the precision error that comes with using IEEE-754 doubles.

http://jibbering.com/faq/


PointedEars
 
P

Paul J. Dudley

It would seem that your problem is not JS, but a lack of programming skills.
Here you are:

window.alert("X = " + 120.85 * 24 / 16);

Beware of the precision error that comes with using IEEE-754 doubles.

http://jibbering.com/faq/


PointedEars
Thanks for the pointer ..

= Paul =
 
P

Paul J. Dudley

It would seem that your problem is not JS, but a lack of programming
skills.

Correct ... but I already mentioned that I was JS illiterate. Years ago
I'd done scripts in Ultrix, VMS command language and a little dabbling
with JS later when it came to be. I did take an intro to "C" programming
- but that was some 15 years ago or so. I never kept up with any of it...

I did manage to hack something I found out there, which is what I should
have
done in the first place instead of wasting y'all's time. My humble
appologies. Just for the record, here is what I came up with. It do give
us a close figure. With direct deposit, our payment shows up on
Wednesday. We don't receive our actual pay stub until Friday. This gives
us an approximate value in the mean time to ascertain we didn't get
screwed ( management has a way of screwing up our payrolls ):

<script language="JavaScript">
<!--
function wage1() {
a = 113.24/17.3;
b = a*document.form1.b.value;
document.form1.total1.value = b
}
//-->
</script>

<form name="form1">
<table border="1" cellpadding="1" cellspacing="1">
<tbody>
<tr>
<td colspan="3" align="center"><b><font size="4">Approx. Take Home
Pay</font></b>
</td>
</tr><tr>
<td>Hours worked <input size="5" name="b">?</td> <td>Approx:$ <input
maxlength="10" size="5" name="total1"></td> <td><input
onclick="wage1()" value="Calculate" type="button"></td>
</tr>

<tr>
<td colspan="3" align="center"><input value="Reset" type="reset"></td>
</tr>
</tbody> </table> </form>
 
P

Paul J. Dudley

It would seem that your problem is not JS, but a lack of programming
skills.

Correct ... but I already mentioned that I was JS illiterate. Years ago
I'd done scripts in Ultrix, VMS command language and a little dabbling
with JS later when it came to be. I did take an intro to "C" programming
- but that was some 15 years ago or so. I never kept up with any of it...

I did manage to hack something I found out there, which is what I should
have done in the first place instead of wasting y'all's time. My humble
appologies. Just for the record, here is what I came up with. It do give
us a close figure. With direct deposit, our payment shows up on
Wednesday. We don't receive our actual pay stub until Friday. This gives
us an approximate value in the mean time to ascertain we didn't get
screwed ( management has a way of screwing up our payrolls ):

<script language="JavaScript">
<!--
function wage1() {
a = 113.24/17.3;
b = a*document.form1.b.value;
document.form1.total1.value = b
}
//-->
</script>

<form name="form1">
<table border="1" cellpadding="1" cellspacing="1">
<tbody>
<tr>
<td colspan="3" align="center"><b><font size="4">Approx. Take Home
Pay</font></b>
</td>
</tr><tr>
<td>Hours worked <input size="5" name="b">?</td> <td>Approx:$ <input
maxlength="10" size="5" name="total1"></td> <td><input
onclick="wage1()" value="Calculate" type="button"></td>
</tr>

<tr>
<td colspan="3" align="center"><input value="Reset" type="reset"></td>
</tr>
</tbody> </table> </form>
 
T

Thomas 'PointedEars' Lahn

Paul said:
Correct ... but I already mentioned that I was JS illiterate.

And I said it is not really a JavaScript problem, but a programming problem.
[...]
I did manage to hack something I found out there, which is what I should
have done in the first place instead of wasting y'all's time. My humble
appologies. Just for the record, here is what I came up with.

I think you could have used your time better than this. Hints are all over
this newsgroup, especially this week. I'll be as concise as possible, if
you have any questions after you did research on existing articles, feel
free to ask.
It do give us a close figure. With direct deposit, our payment shows up on
Wednesday. We don't receive our actual pay stub until Friday. This gives
us an approximate value in the mean time to ascertain we didn't get
screwed ( management has a way of screwing up our payrolls ):

<script language="JavaScript">

<script type="text/javascript">

See http://validator.w3.org/

Remove that nonsense.
function wage1() {
a = 113.24/17.3;
b = a*document.form1.b.value;

var a = ...;
var b = a * document.forms["form1"].elements["b"].value;
document.form1.total1.value = b

document.forms["form1"].elements["total1"].value = b

However, it can be written more efficient, see below.

Remove that line.
</script>

<form name="form1">

<form action="" name="form1">

But your form does not need a name, see below.
<table border="1" cellpadding="1" cellspacing="1">

Use CSS instead.
<tbody>
<tr>
<td colspan="3" align="center"><b><font size="4">Approx. Take Home
Pay</font></b>

Don't use the deprecated `font' element, use CSS instead. Since it is a
heading, you don't need CSS (but you can use it); use a hX element to mark
that up as a heading.
</td>
</tr><tr>
<td>Hours worked <input size="5" name="b">?</td> <td>Approx:$ <input
maxlength="10" size="5" name="total1"></td> <td><input
onclick="wage1()" value="Calculate" type="button"></td>
</tr>

<tr>
<td colspan="3" align="center"><input value="Reset" type="reset"></td>
</tr>
</tbody> </table>
</form>

You don't need a table at all with this approach, some DIVs suffice.
However, it would be better if you used a table for what it is, a
means to display tabular information.

<h1 style="text-align: center">Approx. Take Home Pay</h1>

<form action="">
<script type="text/javascript">
function wage1(o)
{
o.form.elements["total1"].value =
113.24/17.3 * o.form.elements["b"].value;
}
</script>

<table>
<tr>
<th style="text-align: left">Hours worked:</th>
<td><input name="b" size="5"></td>
</tr>
<tr>
<th style="text-align: left">Approx. ($):</th>
<td><input name="total1" maxlength="10" size="5" readonly></td>
</tr>
</table>

<div>
<script type="text/javascript">
document.write(
'<input type="button" value="Calculate" onclick="wage1(this)">');
</script>
<input type="reset" value="Reset">
</div>
</form>


Please provide proper attribution, see
http://www.jibbering.com/faq/faq_notes/clj_posts.html


HTH

PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,883
Members
47,414
Latest member
djangoframe

Latest Threads

Top