JavaScript Chrome console - uncaught referenceerror

I must have missed a course (or am yet to get to it) but I am stuck trying to follow the data structures course with inspecting objects printed in the console, as well as use the console to define new objects like a ‘stack’

The console doesn’t display the solid ‘>’ dropdown mark meaning inspection isn’t possible for me, and I get an error (mentioned in title) when trying to create a ‘stack’

I’m doing something wrong but after hours of creative searching I cannot find any resource to help me on my way here… any help would be much appreciated

TIA

Could you upload your code and error captures?

Sure, no problem!

can you upload your code ?

This is where I feel I have missed a step/tutorial…

I’m following along with Mosh using VSCode, IntelliJ, et al. and the built-in terminals/consoles, suddenly he switches to executing in a browser console and I cannot continue without returning the error in the image

Normally Mosh would run through basic tools in a course but this seems to have gotten past me somehow

Do you have problem using live server in VsCode? because when i saw this post and went to check my code the server just runs and i should go to browser by myself and give it the address, before that it would just run the browser by itself and i did try everything from last night and today but nothing worked :disappointed:

I haven’t any problems displaying code using Live Server, but the problem persists in console regardless… I’ve tried using different browsers on both Windows and Macs, even using Node app and the same error is returned, hence the thinking I’ve skipped steps

I suppose it’s ok and I can assume what Mosh is teaching (properties, inheritance, prototypes, etc.) is happening in the background, but I really would like to have created my own examples as this is all still relatively new to me

Try this code, see what happens


 class Stack {

   constructor() {

     _items.set(this, []);

   }

   push(obj) {

     _items.get(this).push(obj);

   }

   pop() {

     const items = _items.get(this);

     if (items.length === 0) {

       throw new Error("Stack Is Empty!");

     }

     return items.pop();

   }

   peek() {

     const items = _items.get(this);

     if (items.length === 0) {

       throw new Error("Stack Is Empty!");

     }

     return items[items.length - 1];

   }

   get count() {

     return _items.get(this).length;

   }

 }
1 Like

Thanks buddy you’ve helped me solve this and bridge a few ‘knowledge gaps’ as well, was able to execute the declarations live in the console window

I know this is/was entry-level stuff you’ve helped me with, and I am grateful for the assistance

No problem, glad to help you :slightly_smiling_face: :heart: