1.6 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 6610c538372aa61cc0f5b122 | Step 57 | 1 | step-57 |
--description--
Variables in JavaScript are available in a specific scope. In other words, where a variable is declared determines where in your code it can be used.
The first scope is the global scope. Variables that are declared outside of any "block" like a function or for loop are in the global scope. Your character, count, and rows variables are all in the global scope.
When a variable is in the global scope, a function can access it in its definition. Here is an example of a function using a global title variable:
const title = "Professor ";
function demo(name) {
return title + name;
}
demo("Naomi")
This example would return "Professor Naomi". Update your padRow function to return the value of concatenating your character variable to the beginning of the name parameter.
--hints--
Your padRow function should concatenate character to the beginning of name.
assert.match(padRow.toString(), /character\s*\+\s*name/);
Your padRow function should return the result of character + name.
assert.equal(padRow("Naomi"), "#Naomi");
--seed--
--seed-contents--
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
function padRow(name) {
return 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);