Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8336991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:09:36+00:00 2026-06-09T04:09:36+00:00

That’s a code fragment task – you should enter var (as many as want)

  • 0

That’s a code fragment task – you should enter “var” (as many as want) in it in order to get 17 in the first, and 21 in the second alert. I thing that I have met this before, but still was not able to solve the issue.

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);

If you put “var” in the function in front of b, it will alert “17”. The next alert gives us 46 because of the new value of b, return by the function.

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

That’s the source of the task:

http://www.codecademy.com/courses/javascript-for-jquery/1?curriculum_id=4fc3018f74258b0003001f0f/#!/exercises/3

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:09:37+00:00Added an answer on June 9, 2026 at 4:09 am

    Using exactly what’s given, in exactly the way it’s given is impossible.

    What I mean by that is if the call:

    c = line(a) + b;
    

    is dependent upon the value of b which is the assignment at:

    b = line(a) - b;
    

    Then it’s 100% impossible to either have made a a significantly-small number, or made b a significantly-large negative number to make the math work.

    Therefore it’s my belief that they’re intended to be two separate checks.

    Best-case scenario, if we’re trying to have b=17 included:

    a = 3;
    3 * 5 = 15 + 4 = 19 + 4 = 23;
    

    That’s the smallest you’re going to get, assuming you run the two back-to-back.
    Even if you did it that way, you wouldn’t get b = line(a) - b = 17 on the first run…

    If it was written:

    c = line(a) - b;
    d = line(a) + b;
    

    Then you could run both in succession and get the expected result.

    Or you can run:

    var a = 3,
        b = 2;
    
    function line (x) {
        var a = 5,
            b = 4;
        return a*x + b;
    }
    
    b = line(a) - b;
    

    and get 17.

    Then you can run:

    var a = 3,
        b = 2;
    
    function line (x) {
        var a = 5,
            b = 4;
        return a*x + b;
    }
    
    c = line(a) + b;
    

    (ie: the exact same setup with a different instigator, and without the saved b value from the return of the previous call), and get the desired result.

    But it’s not possible to run both of them one after the other, and expect to have them both work, without doing anything to the code but add a var or four.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's it. How can I get the old value of a textarea in order
that's part of my script: var count = $(.sliderItem).length; if (count < lp +
That should be simple web site but with an editable tree. This tree will
That's what i want to do <ul> <li> <a href=# alt=1> User1 </a> <li>
I have a French site that I want to parse, but am running into
That is, is there ever a case where a domain model should be available
That's what I want to know. If I have to encrypt the cookie value
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That is to say, if I set an animation to take 1 second, will
That's it . I want to open all the files in once (to make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.