代码优化oooooo

function mosaicZero(var num) {

    //根据num拼接字符串zero,数字num是几字符串zero就有几个0.num取值范围0-16

    var zero = "";

    if (num == 0) zero = "0";

    if (num == 1) zero = "00";

    if (num == 2) zero = "000";

    if (num == 3) zero = "0000";

    if (num == 4) zero = "00000";

    if (num == 5) zero = "000000";

    if (num == 6) zero = "0000000";

    if (num == 7) zero = "00000000";

    if (num == 8) zero = "000000000";

    if (num == 9) zero = "0000000000";

    if (num == 10) zero = "00000000000";

    if (num == 11) zero = "000000000000";

    if (num == 12) zero = "0000000000000";

    if (num == 13) zero = "00000000000000";

    if (num == 14) zero = "000000000000000";

    if (num == 15) zero = "0000000000000000";

    if (num == 16) zero = "00000000000000000";

    return zero;

}


长风秋雁
浏览 545回答 1
1回答

当年话下

var num = 5;var result = "00000000000000000".substr(0, num);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript