console.log()
语句将准确打印您告诉他们打印到浏览器控制台的确切次数。在浏览器中的文本编辑器中,过程略有不同,最初可能会让人感到困惑。传递给文本编辑器块中的console.log()
值运行每组测试以及您在代码中进行的任何函数调用的一次。这有助于一些有趣的行为,并且可能会在开始时将您绊倒,因为您希望只看到一次的记录值可能会打印出更多次,具体取决于测试次数和传递给这些测试的值。如果您只想查看单个输出而不必担心运行测试周期,可以使用console.clear()
。 console.log()
在指示的代码中打印变量。 console.log()
打印outputTwo
变量。在浏览器控制台中,这应该打印出变量的值两次。
testString: 'assert(code.match(/console\.log\(outputTwo\)/g), "Use console.log()
to print the outputTwo
variable. In your Browser Console this should print out the value of the variable two times.");'
- text: 使用console.log()
打印outputOne
变量。
testString: 'assert(code.match(/console\.log\(outputOne\)/g), "Use console.log()
to print the outputOne
variable.");'
- text: 使用console.clear()
修改输出,以便outputOne
变量只输出一次。
testString: 'assert(code.match(/^(\s*console.clear\(\);?\s*)$/gm), "Use console.clear()
to modify your output so that outputOne
variable only outputs once.");'
```