Announcement Announcement Module
Collapse
No announcement yet.
basic javascript question Page Title Module
Move Remove Collapse
Search Search Module
Collapse

Advertisement Advertisement Module
Collapse

Featured Images Featured Images Module
Collapse

Mediabistro Creative Sites Mediabistro Creative Sites Module
Collapse
Latest Topics Latest Topics Module
Collapse

  • skribe
    Reply to Where can I find help with vehicle graphic design?
    skribe
    I designed and applied vinyl car graphics and wraps for a number of years when I was working in the sign industry.

    It is true that door handles are best avoided, but sometimes it is not possible,...
    Today, 09:12 AM
  • guiri
    Reply to Where can I find help with vehicle graphic design?
    guiri
    The back is much easier 'cause the excursion has a big back window and being that it's a big truck, the whole thing is pretty wide but I also want something on the sides so I can be seen from all sides....
    Today, 07:42 AM
  • <b>
    Reply to My Life in Typefaces - Matthew Carter
    <b>
    I really didn't define what I meant by important. For that matter, I'll still leave it fuzzy since there's really no way to objectively measure such a thing.

    As for Comic Sans, I'd say it's...
    Today, 06:01 AM
  • guiri
    Reply to Where can I find help with vehicle graphic design?
    guiri
    ISitude, thanks. You know, things would be soo much simpler if people just did what they're supposed to. ESPECIALLY if they have gotten paid. Oh well. Anyway, wraps are cool as hell and although I really...
    Today, 05:30 AM
  • ISitude
    Reply to My Life in Typefaces - Matthew Carter
    ISitude
    True that <b>. .. and Comic Sans is on most computers too ...sigh.

    To me Zuzana's work is most notable because of the contribution to creating bitmap fonts from the most early days......
    Today, 03:46 AM
Advertisement Advertisement Module
Collapse

Sponsors Sponsors Module
Collapse

X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • basic javascript question

    how do i make this function display properly?
    The alert do not add the numbers, instead they treat it as strings i guess and alerts "The total value is 5711" when i want it to say "The total value is 23"

    <html>
    <body>

    <script type="text/javascript">

    /* Avoiding errors using typeof operator */

    function addThree(arg1, arg2, arg3)
    {

    if ( (typeof arg1 !="number") || (typeof arg2 !="number") || (typeof arg3 !="number") )
    alert("Please input only numbers!");
    else
    alert("The total value is "+arg1+arg2+arg3);
    }

    var x=5, y=7;
    addThree(x, y , 11);


    </script>

    </body>
    </html>

  • #2
    If you use + on a number, it converts it to a string I think. + is used to concatenate strings, variables, etc.

    However, adding up nothing but integers works fine. What you are doing, is adding a string, then 3 numbers, which wont work.

    HTML Code:
    <script type="text/javascript">
    
    function addThree(arg1, arg2, arg3)
    {
    	if ( (typeof arg1 !="number") || (typeof arg2 !="number") || (typeof arg3 !="number") )
    	{
    		alert("Please input only numbers!");
    	}
    	else
    	{
    		total = arg1+arg2+arg3;
    		alert("The total value is " + total);
    	}
    }
    
    addThree(1,2,3);
    
    </script>

    Comment


    • #3
      I see, so you would have to set the total of the arguments in a variable first and then declare that variable with the string.

      thanx

      Comment

       
      home | site map | advertising/sponsorships | about us | careers | contact us | help courses | browse jobs | freelancers | events | forums | content | member benefits | reprints & permissions about | terms of use | privacy policy | Copyright © 2014 Mediabistro Inc. Mediabistro Inc. call (212) 389-2000 or email us
      Working...
      X