SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to Multiplie in javascript?

    How can I Multiply two variables with each other?
    when I do like this:

    a = 2
    b = 2
    c = a+b

    c = 22

    And it should be 4

    Thanks for your time

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    a = 2 ; b = 2 ; c = a + b;
    This produces 4 for me in the firefox javascript console (btw, that's addition, not multiplication). Are you sure they aren't declared as characters?

  3. #3
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    of course it is, I'm just being stupid


    Anyway, how do I see if they are declared as characters or not? and how do I change it?

    In the script I tried to get working I used prompt popups to make the a and b variable, maybe this is a stupid way of doing it?

  4. #4
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could do something like Math.abs(a) + Math.abs(b) (of course this example will work with positive numbers only)

  5. #5
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm well, this isn't really anything I make to use Just trying to understand javascript a bit better so I figure I should make a couple useless scripts before I can actully make something usefull. Anyway, I'll try do it that way, if anyone know any other way please say so


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
  •