On the problem of variables

 var i=1;
      function changeColor(bg,num){
         
          box.style.color=bg;
          box.innerHTML=(iPP)*num;
          
          
       }        
         
      btn1.onclick=function(){
         
         changeColor("red",1);
       
       }
        
      btn2.onclick=function(){
          
         changeColor("green",2);
          
       }
         
      btn3.onclick=function(){
          
         changeColor("yellow",3);
          
       }//
       
Mar.04,2021

is not clear enough. If you want the global variable I to be 1 every time, just define it in the changeColor function.


var i=0, color = "";
function changeColor(bg,num){
    if(color !== bg) {
        i = 0;
        color = bg;
        box.style.color=bg;
    }//0
    box.innerHTML=(iPP)*num;
 }        
   
btn1.onclick=function(){
   
   changeColor("red",1);
 
 }
  
btn2.onclick=function(){
    
   changeColor("green",2);
    
 }
   
btn3.onclick=function(){
    
   changeColor("yellow",3);
    
 }//

reset when clicked

Menu