Wrox Programmer Forums code not working
 |
 Javascript How-To Ask your "How do I do this with Javascript?" questions here.
 Welcome to the p2p.wrox.com Forums. You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com

December 16th, 2003, 12:31 PM
 Toka1 Authorized User Join Date: Nov 2003 Posts: 21 Thanks: 0 Thanked 0 Times in 0 Posts

Thanks Joe

I will alter that, could you also tell me how I change a negative number to positive. Or an alternative to how I could code this.

var b="-" + tonum(form.inputbox2.value);

//Calculation of Discriminent
var d

if (b<=-6 && b>=-20)
{
d=b*b-(4*0.2253*-194.4);
}
else if (b<=-21 && b>=-52)
{
d=b*b-(4*0.2253*-134.4);
}
else if (b <-52)
{
d= (b*4.635);
}

I will change the top line as you suggested.

In the above code for the first two conditions I need the input changing to a negative number.

But the last condition "d= (b*4.635);" I need b to stay as a positive input here.

So I need to now change this back to a positive number or write the negative line that you have helped me with to only correspond to the first two conditions.

Can you help at all

Thanks

Toka

December 16th, 2003, 12:47 PM
 joefawcett Wrox Author Join Date: Jun 2003 Posts: 3,074 Thanks: 1 Thanked 38 Times in 37 Posts

If I understand you correctly why not leave b as positive? As you are squaring it anyway it seems odd.
You could also calculate the fixed stuff. Assuming b is just the numeric value entered into the textbox:
Code:
```if (b >= -6 && b <= -20)
{
d=b*b-(4*0.2253*-194.4); //calculate 4*0.2253*-194.4 in advance here
}
else if (b >= 21 && b <= 52)
{
d=b*b-(4*0.2253*-134.4);
}
else if (b > 52)
{
d= (b*4.635);
}```
--

Joe

December 17th, 2003, 05:08 AM
 Toka1 Authorized User Join Date: Nov 2003 Posts: 21 Thanks: 0 Thanked 0 Times in 0 Posts

Hi Joe

I cannot leave b as positive or the calculation won't work.

The user will enter a positive number, to do the calculation in the first two instances it will only work on a negative number.

Therfore I need the input changing to a negative number for the first two conditions for the calculation to work and output the required result.

However the 3rd condition as the calculation is simpler works on the positive number input.

Calculating the fixed stuff is a great idea, Thanks

 Similar Threads Thread Thread Starter Forum Replies Last Post Working Code - Ch15 slurp56 BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 3 April 24th, 2013 10:32 AM Code not working billytikky88 C# 1 February 17th, 2008 03:20 PM Code not working well vinish Beginning PHP 2 November 11th, 2005 08:02 PM Select From Where Code not working...help bidatad Access VBA 2 April 1st, 2005 03:25 PM Working with code behind - How To pinkuisadear ASP.NET 1.0 and 1.1 Basics 7 March 11th, 2005 01:13 AM