Data Structures - Learn how a Stack Works

Tell us what’s happening:
Describe your issue in detail here.

I was certain before doing the challenge, but confirmed the solution matches mine as well, but for some reason my solution keeps receiving the warning

The initial declaration of the homeworkStack should not be changed. It seems to be a bug.

Your code so far

var homeworkStack = ["BIO12","HIS80","MAT122","PSY44"];
// Only change code below this line

let top = homeworkStack.pop();

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/112.0

Challenge: Data Structures - Learn how a Stack Works

Link to the challenge:

The error seems clear. You’re changing the homeworkStack declaration.
For the test to pass, you must not change any line before the comment (the line starting with // ).
If you’re not figuring out whats wrong, please post your code so we can review it.

My code is listed there as “Your code so far”.

My code, with the exception of the console.log statements, is exactly like the solution provided when a user asks for a hint.

Errrm, not it’s not… you have another variable (top) in there too. What’s that for?

That is just a variable I used to catch the value that is popped() to confirm that the correct value popped.

Commenting out that code, or removing it altogether, does not resolve the issue of the failing test (“The initial declaration of the homeworkStack should not be changed”) and therefore seems moot, however, you are correct that it is different than the solution provided in the “Get a hint” section". However, when I copy the code from that section verbatim, I still end up with that failing test.

To be fair, the error message isn’t helpful (or accurate).

However, if I paste the solution in, it passes.
If you remove the extraneous variable from your code (but keep the pop statement), it should pass too.

I tried it again, and it worked, which is frustrating…

I’m not sure what I was doing before that caused it not to pass, but it did.

What is most frustrating is that capturing the popped value in a variable (in my mind - which I would be more than happy to have changed) isn’t changing the initial declaration of the homeworkStack, and therefore shouldn’t cause that test to fail (as you said, it’s not a helpful error to begin with).

Sorry for venting, it just seemed such a trivial thing to cause a test to fail.

Thanks for your help.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.