write a javascript multiplication function that will return two separate results

前端 未结 4 445
长情又很酷
长情又很酷 2021-01-27 01:11

As you can see from the embed below... my script is only returning one result(500). How can I rewrite my code so that I get both results? Thank you in advance for your advice.

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-27 01:50

    You can try the following approach

    function multiplier() {
        var number = 25;
        var multiplier20 = 20;
        var res1 = 0;
        var res2 = 0;
        if (number && multiplier20); {
            res1 =  number * multiplier20;
        }
        var multiplier1 = 1;
        if (number && multiplier1); {
            res2 =  number * multiplier1;
        }
        return {res1,res2};
    }
    var ret = multiplier();
    console.log(ret);

提交回复
热议问题