1.6 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 6610c6541c82551f95e765ab | Step 58 | 1 | step-58 |
--description--
Variables can also be declared inside a function. These variables are considered to be in the local scope, or block scope. A variable declared inside a function can only be used inside that function. If you try to access it outside of the function, you get a reference error.
To see this in action, use const to declare a test variable in your padRow function. Initialise it with the value "Testing".
Then, below your function, try to log test to the console. You will see an error because it is not defined outside of the function's local scope. Remove that console.log to pass the tests and continue.
--hints--
Your function should declare a test variable.
assert.match(padRow.toString(), /var\s+test/);
You should initialise test with the value "Testing". Don't forget the semi-colon.
assert.match(padRow.toString(), /var\s+test\s*=\s*('|")Testing\1;/)
Your test variable should come before your return keyword.
const str = padRow.toString();
assert.isBelow(str.indexOf("test"), str.indexOf("return"));
--seed--
--seed-contents--
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
function padRow(name) {
return character + name;
}
--fcc-editable-region--
const call = padRow("CamperChan");
console.log(call);
for (let i = 0; i < count; i = i + 1) {
rows.push(character.repeat(i + 1))
}
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);