Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get Practice 03_12 to work. #8

Open
mmarras opened this issue Mar 12, 2021 · 14 comments
Open

Cannot get Practice 03_12 to work. #8

mmarras opened this issue Mar 12, 2021 · 14 comments

Comments

@mmarras
Copy link

mmarras commented Mar 12, 2021

Issue Overview

Scope issue with classes.

Describe your environment

Windows 10 19041, Chrome 88 or Edge, atom 1.55.0, atom-live-server

Steps to Reproduce

Working directly in the file structure provided, I add the following to the empty script.js.

import Backpack from "./Backpack.js";

const mybackpack = new Backpack(
  'test',
  10,
  'red',
  10,
  26,
  26,
  false);

console.log('Values of mybackpack', mybackpack)

In the browser console it prints the mybackpack as I expect. But if I then try to access mybackpack.name or anything of mybackpack it returns the following error:

Uncaught ReferenceError: mybackpack is not defined
at <anonymous>:1:1

Expected Behavior

Being able to access mybackpack from the console as in previous chapters.

Current Behavior

mybackpack is not part of the scope.

Possible Solution

Copying the class definition of Backpack into script.js and and removing pointers to Backpack.js (in index.html as well as in script.js) helps.

To be honest, I think the presence of Backpack.js is just confusing for this exercise and not needed to work through the given tasks.

Screenshots / Video

Related Issues

@AndrewIzatt
Copy link

I am having the same error when using this exercise file ("03_12")

@Morticia007
Copy link

Morticia007 commented Nov 9, 2021 via email

@AndrewIzatt
Copy link

Thanks for such a quick response! But I keep getting this error:
image

@Morticia007
Copy link

Morticia007 commented Nov 10, 2021 via email

@Morticia007
Copy link

Morticia007 commented Nov 10, 2021 via email

@AndrewIzatt
Copy link

So if by server you mean nodejs yeah I do. I'm super new to this stuff but this is what my VSCode shows along the bottom in the far right corner:
image

I'm wondering if there is perhaps something else wrong and not just the files though because when I was trying to complete the challenge at the end of this chapter (ch. 3) I tried just recreating exactly in new files what Morten had made in order to create different instances of my own self-created classes and I'm still getting this error when I try and call that instance and an attribute in the console window so now I don't think it's just the files that are the problem. There's gotta be something else. Here's the same error:
image

@AndrewIzatt
Copy link

Sorry that was a long sentence! lol

@Morticia007
Copy link

Morticia007 commented Nov 10, 2021 via email

@AndrewIzatt
Copy link

AndrewIzatt commented Nov 11, 2021

Wow thank you so much for your help. I really didn't expect this much attention. But I am very grateful!
I had had my VSCode port in the corner running for a while so I reset it and then started it again. As you can see I am getting the same error:
image

Here is my HTML:
image
Here is my JavaScript (main):
image
Here is my Instrument class in a separate JavaScript file:
image
And finally here is my Drink class:
image

Thank you again. You've been more than helpful for helping me with this.

@Morticia007
Copy link

Morticia007 commented Nov 11, 2021 via email

@Morticia007
Copy link

Morticia007 commented Nov 11, 2021 via email

@Morticia007
Copy link

Morticia007 commented Nov 11, 2021 via email

@AndrewIzatt
Copy link

Wow thank you so much. I'm super new to JavaScript (I just started this week!) so I don't really understand what you're saying but I'm glad to know at least my syntax isn't wrong. I'd have wished that LinkedIn Learning's files would be airtight but I guess you can't even count on that. This really derailed me for a while trying to figure out what the issue was before I posted my question so thank you so much for your help!

@Morticia007
Copy link

Morticia007 commented Nov 12, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants