Your task is to drive your car from 1 to 60 Kilometers per hour by printing a pattern.
A hyphen represents the speed of cars.
one hyphen is counted as 1 kph.
简单来讲就是依次输出1到60个连字号。
(题目来源于此)[https://edabit.com/challenge/...]。
function Go(num) { var result = ""; for(var i=0; i<num; ++i){ result+="-"; } return result; }
num是从1到60依次测试的。所以实际上应该看到1到60个“-”依次输出。如“-”,“--”,“---”。以上代码是正确的,但我尝试着把
var result = "";
改成
var result;
结果就会报错。这是为什么呢?一定要先定义result为字符串吗?
Smart猫小萌
蛊毒传说
相关分类