sum of the digits of a number javascript

后端 未结 4 857
无人及你
无人及你 2021-01-04 13:07

I saw a bunch of other posts on this topic but none in javascript. here is my code.

var theNumber = function digitAdd (base, exponent) {
    var number = 1;
         


        
4条回答
  •  旧时难觅i
    2021-01-04 13:51

    Not sure what you meant, In case you were asking about while loop..

    The while statement continually executes a block of statements while a particular condition is true. Its syntax can be expressed as:

    while (expression) {
         statement(s)
    }
    

    The while statement evaluates expression, which must return a boolean value. If the expression evaluates to true, the while statement executes the statement(s) in the while block. The while statement continues testing the expression and executing its block until the expression evaluates to false.

    The while loop here is extracting digits one by one from the actual number and adding those. Try to do each step manually and you will get it.

提交回复
热议问题