Unit 4 Lesson 13 bubble 4 on student project: redefinition of " x" and Read Only?

[Posts in the debugging category need to have the following pieces of information included in order to help other teachers or our moderator team best help you. Feel free to delete everything in brackets before posting your request for debugging help.]

Link to the project or level: [https://studio.code.org/s/csp4-2020/stage/13/puzzle/4?section_id=2843583&user_id=20293716&viewAs=Teacher]
What I expect to happen: [expected: get text of location “chooser2”]
What actually happens: [It retrieves the text but there is a yellow triangle stating “Read only” and is seems to be in conjunction with my variable that has a yellow triangle for var location (error message redefinition of “location”]
What I’ve tried: [renamed the var with location1]

Hello,

Unfortunately I am unable to see the work of your students via that link. (It just brings me to my version of stage 13 puzzle 4!) In order for others to see it, would you please go to that level and click ‘share’, then paste the link in this thread?

Okay, I think he had an issue with global and local names being similar. He fixed that but now here is the thing that is tripping us

Link to the project or level: [https://studio.code.org/projects/applab/_khHHRYVNW2x-ZoIOR4zeFHMkbscTFonf5-2CDTODnU] provide the shared link
What I expect to happen: [Display the restaurant name when called on]
What actually happens: [Displays the same name whenever I do a different option than the default setting ("Itallian, 5 miles away, ")] What I’ve tried: [I deleted the code with the same names to test if it worked with the 3 options, if (type=="Itallian" && location1== "5 miles away" && cost== "") {
setText(“result_area”, “You would like TonyD’s New York Pizza & Restaurant”);
} else if (type==“Mexican” && location1== “5 miles away” && cost== “") { setText("result_area", "You would like Salsa's"); } else if (type=="Chinese" && location1== "5 miles away" && cost== "”) {
This code works itself, but whenever the full code is added, the restaurant name defaults to “You would like TonyD’s New York Pizza & Restaurant”. ]

OMG… I feel like such a rookie looking for coding issues… It was, but an easy fix by talking it out

You are now officially a computer programmer. To complete your training you will need to read The Hitchhiker’s Guide to the Galaxy and watch the movie Starship Troopers.

I have a student getting a Read Only error and we can’t figure out what is causing it. We looked at variable scope as a cause. Can someone please explain what a read only error is and what usually causes it?

Hi @rwest1,
A Read Only error occurs when the contents of a location in memory can be read, but not written. Specifically, when storing information in javascript you can use the three keywords: let, var, and const. A const, aka a constant, is something that can be created and never changed.
Generally in CSP we use var and let, but when you run in to a read only error you’re likely trying to write (ie store information) in a const.

If your student has not knowingly created a constant, it might be that they are trying to change something (or create a variable with the same name) as something that exists within the inner workings of App Lab. Changing the name of the variable on the line with the error might do the trick! Otherwise I suggest sharing a remake of the code here so we can take a look.

App Lab only has var. It isn’t anything a student can do.

speed, location, and name are used by App Lab already. So you can’t use them. They are marked read only by App Lab so you can’t accidentally redefine them and really make a mess.

I was under the impression that most variables in App Lab are protected from reuse by including an underscore. App Lab should use name_ and location_ for its own use. Perhaps that could be changed because name and location are prime variables for students making games and whatnot. speed is a turtle function so you can’t use it.