Learn Introductory JavaScript by Building a Pyramid Generator - Step 58

Tell us what’s happening:

in level 58 in javascript i wrote the correct code but its repeatedly saying wrong, i followed the steps said in console and its still getting wrong.

Your code so far

const character = "#";
const count = 8;
const rows = [];


// User Editable Region

function padRow(name) {
  const test;
  test="Testing";
  return character + name;
}
console.log(test);

// User 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 + row + "\n";
}

console.log(result);

Your browser information:

chrome

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 58

  1. When using the const keyword, you can’t declare a variable on one line (as in the line const test;) and initialize it on another line (as in the line test = "Testing";), since that technically counts as reassigning the variable, and the point of the const keyword is to not let you reassign variables. You have to do both on the same line. If you were using the let keyword, on the other hand, this would work.

  2. You need to remove the console.log statement. It’s a statement outside of the padRow() function trying to print a variable (test) that was declared inside that function. A variable declared inside a function does not exist outside of the scope of that function, and therefore cannot be accessed by a statement outside the function.

1 Like