Search code examples
functionactionscript-3button

Button generating a cross sum


I'm looking for a tip for a AS3 script, have no idea how to start there

Button, if clicked the function is executed, which outputs a predefined value as the cross sum of a number string.

Example:

Cross sum should be 10

By clicking on the button, the function generates the number 55 or 82 or 37 or 523, ie numbers with the cross sum 10


Solution

  • Got it now..... the function calculates a number, with the crosssum 50

    function berechnen() {
    var rand = Math.floor(Math.random() * 100000000000)
    var sum = String(rand)
    var qsum = 0;
    for (var i = 0; i < sum.length; i++) {
        qsum += Number(sum.charAt(i));
    }
    if (qsum == 50) {
        summe.text = String(sum);
    } else {
        berechnen()
    }
    

    }