Results 1 to 3 of 3

Thread: help with javascript please!

  1. #1
    Join Date
    Mar 2010
    Posts
    1

    help with javascript please!

    hi

    i dont know if anyone can help me - but im stuck on a smal bit of programming and would appreciate some help.

    i need to write a javascript function called difference ( ) that has the ability to take 2 numbers as arguments and return the difference between them, the number that the query returns always needs to be positive or 0, so the function needs to check for this as well

    can anyone help?

  2. #2
    Join Date
    Feb 2010
    Posts
    570

    Re: help with javascript please!

    see for the number to be always positive you have to just check whether the number is greater then zero or not and if it is greater then zero then you can display the number or else you can display zero in the answer.

    a simple example is given below

    var num1= 5
    var num2 = 8
    var result
    result = num1 - num 2
    var default 1 = 0;

    if (result >0)
    {
    document.write(result );

    }
    else
    {

    document.write( default 1 );

    }


    I hope this will solve your problem.
    Last edited by little-Jacqueline; 08-05-2010 at 10:39 AM.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: help with javascript please!

    Quote Originally Posted by newbie1 View Post
    hi

    i dont know if anyone can help me - but im stuck on a smal bit of programming and would appreciate some help.

    i need to write a javascript function called difference ( ) that has the ability to take 2 numbers as arguments and return the difference between them, the number that the query returns always needs to be positive or 0, so the function needs to check for this as well

    can anyone help?
    Hello there, I was facing a similar problem. So, I tried out the solution that has been provided by little-Jacqueline. To my surprise, the program worked without any issues in the first attempt itself. Thus, this is a sure shot solution to your problem. If you have any more doubts, then just let me know.

Similar Threads

  1. Javascript in IE on HTC HD2
    By dONGsUN in forum Portable Devices
    Replies: 4
    Last Post: 06-10-2010, 05:56 AM
  2. What are the different Events in the Javascript?
    By Sheena_thakkar in forum Software Development
    Replies: 5
    Last Post: 18-12-2009, 08:07 AM
  3. Read XML through JavaScript
    By Zhankana_n in forum Software Development
    Replies: 3
    Last Post: 03-12-2009, 10:41 PM
  4. Javascript using C# WinForm
    By Smita.bendal in forum Software Development
    Replies: 3
    Last Post: 03-12-2009, 04:15 PM
  5. Problem with JavaScript
    By Chintam in forum Software Development
    Replies: 4
    Last Post: 14-03-2009, 12:47 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,829,763.10372 seconds with 16 queries