Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
 
Old February 4th, 2004, 07:34 AM
Authorized User
 
Join Date: Nov 2003
Location: Redcar, Cleveland, United Kingdom.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help!!!

I am writing a function that takes a value from an input box writes it to a variable and converts it to a negative number using the *(-1)and then does some calculations on it if certain conditions are true. However if other conditions are true I need to convert the variable back to a positive number to do some more different calculations to cover some different conditions. How do I convert the variable back to a positive number at this point, without affecting my first if statement.

 
Old February 4th, 2004, 08:15 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

When you first use it you save it and use a local variable for the first part.
Code:
function test(Main, Condition)
{
  var iMain = Main * (-1);
  //Calculations;
  if (Condition)
  {
    iMain = Main;
  }
  var iNew = iMain * 2;  //Or whatever
}
Hope this still isn't those quadratics...



--

Joe
 
Old February 4th, 2004, 09:04 AM
Authorized User
 
Join Date: Nov 2003
Location: Redcar, Cleveland, United Kingdom.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Joe









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.