How to write Mathematical formula with “^” (caret) in JavaScript?

前端 未结 4 621
Happy的楠姐
Happy的楠姐 2021-01-21 17:10

I need some help how to make this math formula in javascript. i have tried searching but couldn\'t really find cause i dont even know what ^ is called in English.

Thank

4条回答
  •  执笔经年
    2021-01-21 17:43

    ^ is the bitwise XOR operator - not what you want. Use the Math.pow function for exponentiation:

    Math.floor( 20 * (Math.pow(1.1, x - 10)) );
    

    Set this up in a function so you can use x for whatever value it may be:

    var eq = function(x) {
        return Math.floor( 20 * (Math.pow(1.1, x - 10)) );
    };
    

提交回复
热议问题