AT22
June 2, 2024, 12:10pm
1
I delete the first two elements of the array, but the problem still remains unsolved. What am I doing wrong?
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
/*while (rows.length < count) {
rows.push(padRow(rows.length + 1, count));
}*/
/*for (let i = count; i > 0; i--) {
rows.push(padRow(i, count));
}*/
// User Editable Region
const numbers = [1, 2, 3];
const unshifted = numbers.unshift(5);
const shifted = numbers.shift() + numbers.shift();
console.log(shifted);
console.log(unshifted);
console.log(numbers);
// User Editable Region
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Challenge Information:
Learn Introductory JavaScript by Building a Pyramid Generator - Step 103
Hi and welcome to the forum.
Declare a shifted
variable, assign it the result of calling .shift()
on your numbers
array, and print the variable.
const shifted = numbers.shift() + numbers.shift();
Very close, but you don’t need to add it to itself like this.
AT22
June 2, 2024, 1:50pm
3
How? Then. I’ve tried averything.
Hello!
Along with the previous suggestion, I think this step requires the code be placed where it is above the unshifted code. The print looks good for the console.log.
AT22:
const numbers = [1, 2, 3];
const unshifted = numbers.unshift(5);
const shifted = numbers.shift() + numbers.shift();
As suggested remove the added " + numbers.shift()"
Move the shifted code to be above the unshifted to pass the step, I believe.
Keep up good work.
AT22
June 2, 2024, 3:21pm
5
Hi, i made that and it’s not working.
ILM
June 2, 2024, 3:33pm
6
what is your code now please?
Please share your new code and make note of any errors or hints that are being displayed.
Hi pkdvalis,
This is very simple, take it one at a time. Start by declaring the shifted variable and the value of the variable should be numbers.shift() and finally console.log the variable you declared at first.
I hope this helps.
ILM
June 2, 2024, 4:29pm
9
Please double check who you are writing to, @pkdvalis is not the person asking for help and doesn’t need an explanation
1 Like
Oh… That was a mistake it was suppose to be @AT22
AT22
June 3, 2024, 7:00am
11
Thank you all for the help. I’ve resolved following the steps of @StaySilent . The last i’ve done was eliminate “+ numbers.shift()” and the unshifted variable. But… “const shifted = numbers.shift()” has to be above the “unshifted” line.
2 Likes
system
Closed
December 2, 2024, 7:01pm
12
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.