2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: 587d7b83367417b2b2512b37
|
2021-03-14 21:20:39 -06:00
|
|
|
|
title: 了解 freeCodeCamp 和浏览器控制台之间的差异
|
2018-10-10 18:03:03 -04:00
|
|
|
|
challengeType: 1
|
2020-09-07 16:09:54 +08:00
|
|
|
|
forumTopicId: 301193
|
2021-01-13 03:31:00 +01:00
|
|
|
|
dashedName: understanding-the-differences-between-the-freecodecamp-and-browser-console
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --description--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-09-03 01:11:45 -07:00
|
|
|
|
你可能已经注意到一些 freeCodeCamp 的挑战有自己的控制台。 这个控制台的行为与浏览器控制台有些不同。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-09-03 01:11:45 -07:00
|
|
|
|
有许多方法可以与 `console` 一起使用来输出消息。 `log`、`warn` 和 `clear` 就是几个例子。 freeCodeCamp 控制台只会输出 `log` 消息,而浏览器控制台会输出所有消息。 当你对你的代码进行修改时,它将自动运行并显示日志。 每次代码运行时,freeCodeCamp 控制台都会被清除。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-09-03 01:11:45 -07:00
|
|
|
|
# --instructions--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-09-03 01:11:45 -07:00
|
|
|
|
首先,打开浏览器控制台,以便查看日志。 要做到这一点,在大多数浏览器上,你可以右击顶部的 freeCodeCamp 导航栏,并点击 `inspect`。 然后在打开的窗口中找到 `console` 选项卡。
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
2021-09-03 01:11:45 -07:00
|
|
|
|
之后,使用 `console.log` 记录 `output` 变量。 查看这两个控制台,可以看到日志。 最后,在你的日志后面使用 `console.clear` 清除浏览器控制台。 查看两个控制台的差异。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-09-03 01:11:45 -07:00
|
|
|
|
# --hints--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-09-03 01:11:45 -07:00
|
|
|
|
你应该使用 `console.log()` 来打印 `output` 变量。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-09-03 01:11:45 -07:00
|
|
|
|
```js
|
|
|
|
|
assert(__helpers.removeWhiteSpace(code).match(/console\.log\(output\)/));
|
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-09-03 01:11:45 -07:00
|
|
|
|
你应该使用 `console.clear()` 来清除浏览器控制台。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
```js
|
2021-02-06 04:42:36 +00:00
|
|
|
|
assert(
|
2021-04-30 00:43:46 +09:00
|
|
|
|
__helpers
|
|
|
|
|
.removeWhiteSpace(code)
|
|
|
|
|
.match(/console.clear\(\)/)
|
2021-02-06 04:42:36 +00:00
|
|
|
|
);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
|
|
|
|
|
2021-09-03 01:11:45 -07:00
|
|
|
|
你应该在你的日志之后清除控制台。
|
2020-09-07 16:09:54 +08:00
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```js
|
2021-09-03 01:11:45 -07:00
|
|
|
|
assert(
|
|
|
|
|
__helpers
|
|
|
|
|
.removeWhiteSpace(code)
|
|
|
|
|
.match(/console\.log\(output\)[\s\S]*console.clear\(\)/)
|
|
|
|
|
);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
|
|
```js
|
2021-09-03 01:11:45 -07:00
|
|
|
|
let output = "Get this to show once in the freeCodeCamp console and not at all in the browser console";
|
2021-01-13 03:31:00 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --solutions--
|
2020-09-07 16:09:54 +08:00
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
|
```js
|
2021-09-03 01:11:45 -07:00
|
|
|
|
let output = "Get this to show once in the freeCodeCamp console and not at all in the browser console";
|
2021-01-13 03:31:00 +01:00
|
|
|
|
|
2021-09-03 01:11:45 -07:00
|
|
|
|
console.log(output);
|
|
|
|
|
console.clear();
|
2021-01-13 03:31:00 +01:00
|
|
|
|
```
|