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

  • Mr.Mag00
    Reply to Ungrouping doesn't work in Ai
    Mr.Mag00
    The gradient is already made! I did create gradients. I may not remember exactly how to do it but I'm not trying to create a gradient here. I have 2 images. Both of them have the 3-part object, each...
    Today, 06:55 PM
  • PrintDriver
    Reply to Critique for my own logo.
    PrintDriver
    your gray shadow on the dog is the exact same contrast as the green lettering. Where they overlap the letters are illegible.
    What's it look like in black and white? (no grayscale)
    Simplify...
    Today, 06:40 PM
  • designzombie
    Comment on Design Management | Graduate Student (SCAD)
    designzombie
    Then the grad program should be titled "Design Process Management." And the principles of good design aren't any more relevant to print than they are to electronic media.
    Today, 06:02 PM
  • farmgeek
    Reply to Critique for my own logo.
    farmgeek
    this version has eyes, nose, mouth knocked out. Dog reflected and moved over......
    Today, 05:06 PM
  • farmgeek
    Comment on Critique for my own logo.
    farmgeek
    Thanks Craig-- good ideas. I don't think this it a total solution but I have a version where I knocked out the eyes and mouth that I'll upload.

    Ultimately It might take something like...
    Today, 04:58 PM
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

      Mediabistro A division of Prometheus Global Media home | site map | advertising/sponsorships | careers | contact us | help courses | browse jobs | freelancers | content | member benefits | reprints & permissions terms of use | privacy policy Copyright © 2015 Mediabistro Inc.
      Working...
      X