<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'newb question, experts plz come in' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'newb question, experts plz come in' posted on the 'JavaScript' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 18 May 2013 07:46:46 -0700</pubDate>
    <lastBuildDate>Sat, 18 May 2013 07:46:46 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>newb question, experts plz come in</title>
      <link>http://www.programmersheaven.com/mb/java-script/255777/255777/newb-question-experts-plz-come-in/</link>
      <description>My first attempt to add two variables and output the result ended in failure. &lt;br /&gt;
Example Code:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
var num1 = prompt("Number 1","Enter");
var num2 = prompt("Number 2","Enter");

var num3 = num1 + num2;
alert("Number 3 is "+num3);
&lt;/pre&gt;&lt;br /&gt;
When I entered (as an example) 10 for number 1, and 15 for number 2, 1015 was the result in the alert box.&lt;br /&gt;
&lt;br /&gt;
The second attempt was a success, where I created a function to add the two numbers:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
function AddValues(term1,term2)
{
    var returnvalue = term1;
       
    for(var i = 0; i &amp;lt; term2; i++)
        {
            returnvalue++;
        }
    return returnvalue;
}
&lt;/pre&gt;&lt;br /&gt;
There may be stupid errors in my code but you get the idea. Now, in the first example, why does it output the numbers as compounded character arrays? Is it because every variable defaults to a char array? If so, how do I change this? I doubt something this basic requires workaround functions like in the second example. Thanks in advance.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java-script/255777/255777/newb-question-experts-plz-come-in/</guid>
      <pubDate>Wed, 21 Apr 2004 11:37:50 -0700</pubDate>
      <category>JavaScript</category>
    </item>
    <item>
      <title>Re: newb question, experts plz come in</title>
      <link>http://www.programmersheaven.com/mb/java-script/255777/255819/re-newb-question-experts-plz-come-in/#255819</link>
      <description>: My first attempt to add two variables and output the result ended in failure. &lt;br /&gt;
: Example Code:&lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
: var num1 = prompt("Number 1","Enter");
: var num2 = prompt("Number 2","Enter");
: 
: var num3 = num1 + num2;
: alert("Number 3 is "+num3);
: &lt;/pre&gt;&lt;br /&gt;
: When I entered (as an example) 10 for number 1, and 15 for number 2, 1015 was the result in the alert box.&lt;br /&gt;
: &lt;br /&gt;
: The second attempt was a success, where I created a function to add the two numbers:&lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
: function AddValues(term1,term2)
: {
:     var returnvalue = term1;
:        
:     for(var i = 0; i &amp;lt; term2; i++)
:         {
:             returnvalue++;
:         }
:     return returnvalue;
: }
: &lt;/pre&gt;&lt;br /&gt;
: There may be stupid errors in my code but you get the idea. Now, in the first example, why does it output the numbers as compounded character arrays? Is it because every variable defaults to a char array? If so, how do I change this? I doubt something this basic requires workaround functions like in the second example. Thanks in advance.&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
The Prompt() function always results in a string, which means that both num variables will also be type-cast as strings. You can force javascript to make them integers, by adding 0 to, when creating the variables:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
  var num1 = prompt("Number 1","Enter") + 0;
&lt;/pre&gt;&lt;br /&gt;
This way the addition will follow the numerical rules.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java-script/255777/255819/re-newb-question-experts-plz-come-in/#255819</guid>
      <pubDate>Wed, 21 Apr 2004 15:50:45 -0700</pubDate>
      <category>JavaScript</category>
    </item>
    <item>
      <title>Re: newb question, experts plz come in</title>
      <link>http://www.programmersheaven.com/mb/java-script/255777/256053/re-newb-question-experts-plz-come-in/#256053</link>
      <description>Thx for replying, but the method u said doesn't work. Is there any other type-cast methods?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: : My first attempt to add two variables and output the result ended in failure. &lt;br /&gt;
: : Example Code:&lt;br /&gt;
: : &lt;pre class="sourcecode"&gt;
: : var num1 = prompt("Number 1","Enter");
: : var num2 = prompt("Number 2","Enter");
: : 
: : var num3 = num1 + num2;
: : alert("Number 3 is "+num3);
: : &lt;/pre&gt;&lt;br /&gt;
: : When I entered (as an example) 10 for number 1, and 15 for number 2, 1015 was the result in the alert box.&lt;br /&gt;
: : &lt;br /&gt;
: : The second attempt was a success, where I created a function to add the two numbers:&lt;br /&gt;
: : &lt;pre class="sourcecode"&gt;
: : function AddValues(term1,term2)
: : {
: :     var returnvalue = term1;
: :        
: :     for(var i = 0; i &amp;lt; term2; i++)
: :         {
: :             returnvalue++;
: :         }
: :     return returnvalue;
: : }
: : &lt;/pre&gt;&lt;br /&gt;
: : There may be stupid errors in my code but you get the idea. Now, in the first example, why does it output the numbers as compounded character arrays? Is it because every variable defaults to a char array? If so, how do I change this? I doubt something this basic requires workaround functions like in the second example. Thanks in advance.&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: The Prompt() function always results in a string, which means that both num variables will also be type-cast as strings. You can force javascript to make them integers, by adding 0 to, when creating the variables:&lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
:   var num1 = prompt("Number 1","Enter") + 0;
: &lt;/pre&gt;&lt;br /&gt;
: This way the addition will follow the numerical rules.&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java-script/255777/256053/re-newb-question-experts-plz-come-in/#256053</guid>
      <pubDate>Fri, 23 Apr 2004 10:14:16 -0700</pubDate>
      <category>JavaScript</category>
    </item>
    <item>
      <title>Re: newb question, experts plz come in</title>
      <link>http://www.programmersheaven.com/mb/java-script/255777/256111/re-newb-question-experts-plz-come-in/#256111</link>
      <description>Multiply by one. You can add to a string, so with + 0 it probably converts the 0 to a string instead of the string to a number, but since you can't multiply a string, it'll have to convert it to a number.&lt;br /&gt;
&lt;br /&gt;
There's also the parseInt() function. It'll convert a string to an integer by stripping off everything past the first non-numeric character - so 123hello45 would just give 123, and hello12345 would give NaN (Not a Number). And the string 123 would return the number 123.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java-script/255777/256111/re-newb-question-experts-plz-come-in/#256111</guid>
      <pubDate>Sat, 24 Apr 2004 04:39:56 -0700</pubDate>
      <category>JavaScript</category>
    </item>
  </channel>
</rss>