Open zilongxuan001 opened 6 years ago
如果num是正数,则字符串重复num次。
num
function repeatStringNumTimes(str, num) { // repeat after me var strNum=str; if(num>0){ for(var i=1;i<num;i++){ str+=strNum; } return str; }else{ return ""; } } repeatStringNumTimes("abc", 3);
The String global object
https://www.freecodecamp.org/challenges/repeat-a-string-repeat-a-string
经验谈20180328
这道题比较简单,但一开始容易做错。
为什么JavaScript不能用str*3呀?为什么str不能乘以一个数字,这在python里是很正常的呀。
str*3
挑战
如果
num
是正数,则字符串重复num
次。代码
结果显示
帮助
The String global object
来源
https://www.freecodecamp.org/challenges/repeat-a-string-repeat-a-string