javascript variable scope of var
<p>I'm learning javascript on site <a href="http://www.codecademy.com" rel="nofollow">http://www.codecademy.com</a>, and met a exercise when I learn the<br>
variable scope in javascript, here is the exercise, what I need to do is make the following code get the expected result by fixing use <code>var</code></p>

<p><strong>The following code behaves unexpectedly because of scope issues. Run it and try to figure out what is going on. Fix it using var</strong></p>

<pre><code>a = 3;
b = 2;

function line(x) {
    a = 5;
    b = 4;
    return a*x + b;
}

//b should be 17
b = line(a) - b;
alert(b);

//c should be 21
c = line(a) + b;
alert(c);
</code></pre>

<p>I tried but can't figure the exercise out</p>
