简体   繁体   中英

From one JS calculator to three JS calculators on one page using new Calculator

I created one working JavaScript Calculator and now I want to have 3 calc on one page like this:

using:

const calculator1 = new Calculator("calculator1"); const calculator2 = new Calculator("calculator2"); const calculator3 = new Calculator("calculator3");

But all the buttons from 3 calculators work only with first calculator. What did I do wrong in my code?

I think its because all the calculators are using the same variable (not sure, I'm new to js and just looked over it quickly) but the easiest solution to your problem that I can think of is to put the calculators in s so they don't interact with each other. Also, it's never a good idea to put the name of the Calculator() the same as the ID of the you put it in. Maybe that will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM