Tell us what’s happening:
The prompt asks to concatenerate “row” to the results variable, from the information given, it seems this is how its done. Is there anything wrong with this code?
Your code so far
const character = "#";
const count = 8;
const rows = [];
for (let i = 0; i < count; i = i + 1) {
rows.push(i);
}
let result = ""
// User Editable Region
for (const row of rows) {
result = result + "row";
}
// User Editable Region
console.log(result);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Challenge Information:
Learn Introductory JavaScript by Building a Pyramid Generator - Step 42
ILM
October 25, 2024, 12:38pm
2
you need to concatenate the row
variable, not a string "row"
Whats the row variable. Is it given in the tutor prompt?
ILM
October 25, 2024, 1:01pm
4
you have written it in a previous step
But the step is asking to append a new string
ILM
October 25, 2024, 1:12pm
6
It’s asking to
use the addition operator to concatenate the row
value to the result
value.
It doesn’t ask to append a new string
I thought thats the meaning of concatenate
ILM
October 25, 2024, 1:14pm
8
concatenate means merging two strings together, the two strings are row
and result
If we are concatenating ‘row’ to ‘result’ , then shouldn’t it look like this?:
for (const row of rows) {
result = result + “row”;
}
ILM
October 25, 2024, 1:33pm
10
no, because you need to concatenate the value of the row
variable, not a "row"
string
But there is no row value in the code as at this step
ILM
October 25, 2024, 1:40pm
12
you created it in the previous step
I thought creating a row value would be something like "let row = ’ '; " or “const row = ’ ';”
ILM
October 25, 2024, 1:58pm
14
it’s also that. The row
variable is the loop variable, created with const row of rows
(see, there is const
there!)
Im still not sure what this row value is…
ILM
October 25, 2024, 2:29pm
16
for each iteration row
is a different value of the rows
array.
You can visualize the code execution with this code: Online JavaScript Compiler, Visual Debugger, and AI Tutor - Learn JavaScript programming by visualizing code
I know, but since there was no value given, doesn’t that mean that ‘row’ is the new string to be concatenated to result?
ILM
October 25, 2024, 2:34pm
18
you need to concatenate row
to result
so that the value inside row
is concatenated, you should not concatenate the literal string "row"
But there is no value for row, unless you mean this:
for (const row of rows) {
result = result + “const row”;
}
booleanmethod9:
for (const row of rows)
row
variable is just created, it’s not have any value yet. But you have written row of rows
. rows
have an array as a value.