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 7430527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:09:19+00:00 2026-05-29T09:09:19+00:00

Okay, so the answer to my question might not be the problem but here’s

  • 0

Okay, so the answer to my question might not be the problem but here’s a go anyway.

Basically this is one part of a calculator program. I need to know how I can take the var y on only the first execution of this function (assuming it will likely be executed repeatedly) and have the variable x be converted to that value and hold that value for each subsequent execution … while still allowing for output.original_value to be changed when another function is called that wants to change its value. This is the only part of my program that I have not been able to figure out.

Essentially I am trying to emulate a common calculator function where if the user presses 1+2 and then = the calculation will render 3 and then will increase by the value of the second number (2 in this case) for each subsequent pressing of = (ie. 1+2=3 = 5 = 7….) my calculator right now is doing the opposite (ie. 1+2 = 3 = 4 = 5 = 6………).

(I have tried many many things… for now at the end of the function I have mathSign = null which prevents the program from being run more than once without another function first reseting the values… I did not leave that part in the posted code because my end goal is to not have to use it.)

function result(){
  var x = output.original_value;
  var y = parseFloat(output.value);

  if(mathSign == '+'){
    output.value = x + y;
  }
  else if(mathSign == '-'){
    output.value = x - y;
  }
  else if(mathSign == '*'){
    output.value = x * y;
  }
  else if(mathSign == '/'){
    output.value = x / y;
  }
  else if(mathSign == 'n^'){
    output.value = Math.pow(x,y);
  }
  else if(mathSign == 'reciprocal'){
    output.value = 1 / output.original_value;
    mathSign = null;
  }
  else if(mathSign == 'sqrt'){
    output.value = Math.sqrt(output.original_value);
    mathSign = null;
  }

  output.result = output.value;
}
  • 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-05-29T09:09:20+00:00Added an answer on May 29, 2026 at 9:09 am

    This ended up being the best way to solve my problem. It is in essence a variable switcher and works amazingly with the rest of my calculator code 🙂

    function variable_toggle(){
      output.variable_toggle;
      if(output.value == mathSign){
        output.value = output.original_value;
      }
      if(output.variable_toggle != false){
        var x = output.original_value;
        var y = parseFloat(output.value);
        output.toggled_value = parseFloat(output.value);
        result(x, y);
        output.variable_toggle = false;
      }
      else{
        var x = parseFloat(output.value);
        var y = parseFloat(output.toggled_value);
        result(x, y);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I might confuse some people who might be able to answer this question,
I asked this question and got an excellent answer (thanks!). Part of the problem
Still no answer...anyone have something better? Okay complex 2 part question here. I have
Okay, two admissions here, one is I'm sure this question has been answered and
Okay I tried asking this question yesterday but i'm not sure if I gave
Okay I know I asked about this before, and the answer was basically cache
EDIT: ANSWER AT BOTTOM OF THIS QUESTION Okay so I've got some generic EF
Okay, I know this question have been asked plenty of times already, but I
This is probably a silly question but I can't seem to find an answer.
This is probably a really easy question to answer, but for some reason I'm

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.