locked
Javascript calculate with + RRS feed

  • Question

  • User932259438 posted

    hello,

    i have two variables.
    var a= 10
    var b= 3

    First I need to calculate 10+3 then after click on button I need increase number for +3.

    After click first time in button 10+3=13, but then after click second is 16, if click third time is 19.

    How to do this with javascript? 

    Thanks.

    Tuesday, January 28, 2020 9:36 AM

Answers

  • User-1780421697 posted
    <script>
    var result = 0;
    
    function sum() 
    {
    
    var i=10;  
    var j=3;  
    if(result===0)
    result = Number(i) + Number(j);  
    else
     result = result+j;
     
    alert(result);
    }
    
    </script>
    
    <input type=button onClick="sum()" value="sum">

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 28, 2020 12:43 PM