* spelling: accidentally * spelling: announce * spelling: assembly * spelling: avoid * spelling: backend * spelling: because * spelling: claimed * spelling: candidate * spelling: certification * spelling: certified * spelling: challenge * spelling: circular * spelling: it isn't * spelling: coins * spelling: combination * spelling: compliant * spelling: containers * spelling: concise * spelling: deprecated * spelling: development * spelling: donor * spelling: error * spelling: everything * spelling: exceed * spelling: exist * spelling: falsy * spelling: faulty * spelling: forward * spelling: handle * spelling: indicates * spelling: initial * spelling: integers * spelling: issealed * spelling: javascript * spelling: length * spelling: maximum * spelling: minimum * spelling: mutable * spelling: notifier * spelling: coordinate * spelling: passport * spelling: perform * spelling: permuter * spelling: placeholder * spelling: progressively * spelling: semantic * spelling: submission * spelling: submit * spelling: translations * spelling: turquoise * spelling: visualization * spelling: without * spelling: registration * spelling: representation
3.1 KiB
3.1 KiB
id, title, challengeType, forumTopicId
id | title | challengeType | forumTopicId |
---|---|---|---|
587d7b83367417b2b2512b37 | Understanding the Differences between the freeCodeCamp and Browser Console | 1 | 301193 |
Description
console.log()
statements the exact number of times you requested.
The freeCodeCamp console will print your console.log()
statements for each test of that challenge, as well as one more time for any function calls that you have in your code.
This lends itself to some interesting behavior and might trip you up in the beginning, because a logged value that you expect to see only once may print out many more times.
If you would like to see only your single output and not have to worry about running through the test cycles, you can use console.clear()
and check the browsers console.
Instructions
console.clear()
to clear the browser console. After that, use console.log
to log the output
variable.
Tests
tests:
- text: You should use <code>console.clear()</code> to clear the browser console.
testString: const removeJSComments = code.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, ''); const noSpaces = removeJSComments.replace(/\s/g, ''); assert(noSpaces.match(/console.clear\(\)/));
- text: You should use <code>console.log()</code> to print the <code>output</code> variable.
testString: const noSpaces = code.replace(/\s/g, ''); assert(noSpaces.match(/console\.log\(output\)/));
Challenge Seed
// Open your browser console.
let output = "Get this to log once in the browser console and twice in the freeCodeCamp console";
// Use console.clear() on the next line to clear the browser console.
// Use console.log() to print the output variable.
// Check the two consoles to see the difference. The freeCodeCamp console should have printed the variable twice, once for each test of this challenge. The browser console should only print the variable once because you cleared it first.
Solution
// Open your browser console.
let output = "Get this to log once in the browser console and twice in the freeCodeCamp console";
// Use console.clear() on the next line to clear the browser console.
console.clear();
// Use console.log() to print the output variable.
console.log(output);
// Check the two consoles to see the difference. The freeCodeCamp console should have printed the variable twice, one for each test of this challenge. The browser console should only print the variable once because you cleared it first.