• Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

Bad Assignment, Logical Operators [closed]

Am learning Javascript in code academy. This is the test I have been given,

"Inside the eat function, create an if statement that returns true only if both hungry and foodHere are true, and false otherwise."

My code below is executing but it has a warning. What could be the problem?

andy's user avatar

  • 1 = is an assignment operator. == is a comparison operator. Even better, use !foodHere instead of foodHere == false . Up to you to figure out what ! means. –  Evan Trimboli Commented Feb 12, 2014 at 10:08
  • they say nothing about a console.log ;-) –  Philipp Sander Commented Feb 12, 2014 at 10:20

4 Answers 4

the problem was, that you tried to assign a value in the condition foodHere = false . If you want to compare things you need == and if you want to be sure that the types are the same use === . But you don't need that condition at all!

The assignment want you to return a boolean value ( true or false ) and not to print something, so i guess your code should look like this:

Philipp Sander's user avatar

Single = is for assignment, == is for comparison

Anyways, you don't need the second comparison since if the first one is false it will always go through the else

Emilio Rodriguez's user avatar

I just want to give additional information for emilioicai's answer, there are two kind of "equal comparison" in JavaScript

  • equal to ( == )
  • exactly equal to ( === )

Reference: http://www.w3schools.com/js/js_comparisons.asp

Sutanto's user avatar

= is for assignment, == is for value comparison and === is for value and datatype comparison. So you can use == while comparing with the false. But this is not the best practice. We always uses '!' negation operator while converting true to false

I am using || operator assuming that any one needs to be false.You can go for && if both false are required

Ankur Aggarwal's user avatar

Not the answer you're looking for? Browse other questions tagged javascript or ask your own question .

  • The Overflow Blog
  • Navigating cities of code with Norris Numbers
  • Featured on Meta
  • We've made changes to our Terms of Service & Privacy Policy - July 2024
  • Bringing clarity to status tag usage on meta sites
  • Feedback requested: How do you use tag hover descriptions for curating and do...

Hot Network Questions

  • Why is たってよ used in this sentence to denote a request?
  • Web App - Set a Max Width or Let it Expand Responsively?
  • Why do these finite group Dedekind matrices seem to have integer spectrum when specialized to the order of group elements?
  • Do temperature variations make trains on Mars impractical?
  • Advice needed: Team needs developers, but company isn't posting jobs
  • Venus’ LIP period starts today, can we save the Venusians?
  • Colorless Higgs
  • Short story or novella where a man's wife dies and is brought back to life. The process is called rekindling. Rekindled people are very different
  • Stargate "instructional" videos
  • Existence of semi-group with local but not global identity
  • Word to classify what powers a god is associated with?
  • Does each unique instance of Nietzsche's superman have the same virtues and values?
  • Simple JSON parser in lisp
  • Dial “M” for murder
  • An interesting example of Horizontal and Vertical Lines in TIKZ?
  • Enigmatic Puzzle 4: Three Leaf Clover
  • Difference between "backpedal" and "change your tune"
  • Polar coordinate plot incorrectly plotting with PGF Plots
  • MOSFETs keep shorting way below rated current
  • ambobus? (a morphologically peculiar adjective with a peculiar syntax here)
  • Does the First Amendment protect deliberately publicizing the incorrect date for an election?
  • Is my encryption format secure?
  • DIN Rail Logic Gate
  • Will the US Customs be suspicious of my luggage if I bought a lot of the same item?

what does bad assignment mean in code.org

Get the Reddit app

Ask questions about programming.

Code.org, Boolean expression problem

I’m on code.org & I’m having a hard time with Boolean expressions, I know my codes messed up but I don’t know why.; my assignment is making two drop downs that work. Once a submit button is pressed the text area will tell you what exotic animal you are based on if you're an extrovert or introvert & your gender. I’m obviously doing something wrong because once I pick any of the options it immediately goes to else & says “You should get a Coati” please help me, thank you in advance. My code :

onEvent("submit", "click", function( ) { vert = getText("vertDropDown"); if ((vert=="Introvert" && gender=="Male")) { exoticAnimal= "hegehog"; } else if (vert&& ("genderDropDown"=="Female")) { exoticAnimal= "axolotl"; } else if (vert&& ("genderDropDown"=="Male")) { exoticAnimal= "fennec fox"; } else if ((vert&&("genderDropDown"=="Female") )) { exoticAnimal= "hyacinth macaw"; } else { exoticAnimal= "coati"; } setText("output","You should get a "+ exoticAnimal); });

By continuing, you agree to our User Agreement and acknowledge that you understand the Privacy Policy .

Enter the 6-digit code from your authenticator app

You’ve set up two-factor authentication for this account.

Enter a 6-digit backup code

Create your username and password.

Reddit is anonymous, so your username is what you’ll go by here. Choose wisely—because once you get a name, you can’t change it.

Reset your password

Enter your email address or username and we’ll send you a link to reset your password

Check your inbox

An email with a link to reset your password was sent to the email address associated with your account

Choose a Reddit account to continue

  • Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

  • Recent Discussions
  • 4.9K All Categories
  • 1.2K Help! with 1.x
  • 333 Workshop
  • 3K Help! with 2.0
  • 343 Chit-Chat

: bad expression: Invalid left-hand side in assignment

Dazakiwi38

[[Open door|Sorter1][$CurrentPos.LocEntry[3] = 5; $CurrentPos.LocWall[3] = 5; $Reset = true; $DoorOpened = true]]
Originally I did try that normal link code method and what i was trying to achieve wasn't working so i wrongly assumed that you couldn't have [] within the link|passage code because it uses them, i was assuming it wasn't passing the values.
// WRONG: The closing square bracket of the array touches the closing pair of the markup, making them ambiguous. [[Go where?|There][$list to ["A", "B"]]] // CORRECT: The closing square bracket of the array is separated from the closing pair of the markup by a space. [[Go where?|There][$list to ["A", "B"] ]]

This forum is now read-only. Please use our new forums! Go to forums

what does bad assignment mean in code.org

What does "bad invocation" typically mean in JS?

I got this notice when I was trying to print out the substring “Melbourne is” from “Melbourne is great”.

console.log("Melbourne is great"(0, 12));

Answer 5382d491631fe9ed34006a4a

When JS sees "Melbourne is great"(0, 12) , it tries to “invoke” (call) "Melbourne is great" assuming it to be a function, and then when it sees that it is not a function, it complains of “bad invocation”.

what does bad assignment mean in code.org

Good spotting!

Popular free courses

Learn javascript.

What does "read only" mean as an error message?

we are getting a read only error message for variables. please help me. what does this mean? and how do we debug it? thanks!

It means you are using a variable name that code.org is also using for their stuff too. I think this is a mistake made by a developer and have already opened a bug months ago.

There is nothing to debug you just change the variable name you are using. For example name and location cannot be used by students. Speed is a function used by the turtle graphics package, so that can’t be used by students.

@sandiferc What variable names are you getting the read-only error for? Please share a link with the code. Also, take look at the App Lab documentation . It has detailed instructions on how to use the interface. Please let us know if you have more questions.

thank you!! very helpful

thank you!! i took a javascript course this summer and am understanding things more deeply now.

Related Topics

Topic Replies Views Activity
Coding and Debugging Help 1 721 December 7, 2020
Coding and Debugging Help 7 7574 January 7, 2021
CS Discoveries 2 972 August 9, 2019
Coding and Debugging Help 3 1037 December 22, 2021
Coding and Debugging Help 4 677 January 19, 2022

COMMENTS

  1. Viewing student progress

    You can view student progress for entire lessons: Or zoom in to look at student progress on individual levels: To change the granularity of the view between lessons and levels, use the "View By" toggle button next to the " Select a course or unit " dropdown menu. The type of each level is denoted in the bar at the top of the progress table:

  2. Assigning Work to Students

    How to automatically play "Read-Aloud" instructions for students. My students are receiving a message regarding age restrictions. How do I turn this off? My students are receiving a message stating, "Your teacher didn't expect you to be here..." NEW: "End-of-lesson" boundaries to better control student pacing.

  3. How can I see when my students last worked on an assigned ...

    To see the last time a student in one of your sections worked on an assigned course, go to the individual level you want to check first. Then do the following: Open the blue Teacher Panel on the right-hand side of the page by clicking on the white arrow. Select the student you want to view progress for in the blue panel that appears.

  4. How do I assign projects to students?

    I came here looking for that answer too. There does not seem to be a way to assign a project to students (not a course, as the previous reply answered). My students are using the Pre-Reader course, so none of the project areas are suitable for them except the Pre-Reader Playlab and the Pre-reader Artist.

  5. Wrong code but it shows correctly

    I think that this is why its cool that students will see code in many different situations during the year in CSD. The code in unit 3 has to be syntactically correct and is procedural(for the most part runs from top to bottom) in nature. The code in unit 4 and 6 also has to be syntactically correct but is event driven. My two cents.

  6. Student Assignments locked

    I would also make sure if they are in the same version of the curriculum (20-21). If those all seem to align, write to [email protected] with specific details like the student name, lesson and levels where you are having the issue. They can take a look at what is going on.

  7. Code.org

    Equality operator. Category: Math. Your apps will sometimes need to check if the values in their code are equivalent or not, and then possibly perform some specific action using an if, if-else, or while block. == returns true if the value on the left-hand side of the operator is equal to the value on the right-hand side of the operator.

  8. Setting Up Sections with Google Classroom Sync

    Step 3: [First-time only] Authorize Code.org to use Google Classroom. The first time you try syncing a section with Google Classroom, you will need to authorize Code.org to use Google Classroom. Click the link that says "To authorize Google Classroom, click here.". You should get something like this:

  9. Code.org Tool Documentation

    Assigning Values. The assignment operator = will assign a new value to your variable. This command assigned 100 to the variable size. The variable must always be on the left side. You would read this command as "size gets 100" since size is getting a new value of 100. Any old values it might have been assigned are lost forever.

  10. Code.org Tool Documentation

    Compares two values - numbers, strings, or other booleans - and returns true if they are not equal, otherwise false. "Hello" != "hello" returns true-- because the strings are slightly different. "3" != 3 returns false-- because the string 3 can be coerced into a number before comparing with 3.(see notes above about the forgiving ==). (2+1) != 3 returns false-- because the arithmetic expression ...

  11. javascript

    0. = is for assignment, == is for value comparison and === is for value and datatype comparison. So you can use == while comparing with the false. But this is not the best practice. We always uses '!' negation operator while converting true to false. var hungry = true; var foodHere = true; var eat = function() {.

  12. Assignment (computer science)

    Assignment (computer science) In computer programming, an assignment statement sets and/or re-sets the value stored in the storage location (s) denoted by a variable name; in other words, it copies a value into the variable. In most imperative programming languages, the assignment statement (or expression) is a fundamental construct.

  13. Unsubmit a project?

    While it is past the student's Sunday deadline for project submission, I wanted to offer a possible solution to this issue, should it occur again in the future. If a student finds that they are unable to unsubmit an assignment/project, have them run the code once. From a previous surfacing of this problem, that seemed to allow the Unsubmit ...

  14. PDF Instruction Explanation Assignment, Display, and Input

    The arithmetic operators +, -, *, and / are used to perform arithmetic on a and b. For example, 3 / 2 evaluates to 1.5. Evaluates to the remainder when a is divided by b. Assume that a and b are positive integers. For example, 17 MOD 5 evaluates to 2. Evaluates to a random integer from a to b, including a and b.

  15. How do I assign work to my students via Google Classroom?

    Go to the unit or course overview page for the lesson you want to assign ( example unit overview page and example course overview page) Tap the the "Send to Students" button on the Lesson you want to assign in Google Classroom. Note: previously the Google Classroom button showed up here, but it is now behind the "Send to Students" button.

  16. Code.org, Boolean expression problem : r/AskProgramming

    costanzadev • 1 yr. ago. Firstly, get the value of the gender drop down in the same way as you did with the introvert, so: gender = getText("genderDropDown"); And then, in your if statements, you only want to be checking what values vert and gender are equal to. You do not want part of your conditions being like this:

  17. Embed Code Assignments to other websites

    Personally, I use screenshots from the assignments and projects when I am referring to them in Nearpod. Nearpod does have the option to add a video. I could do a screen recording (Screencastify or Loom) of a Code.org assignment, especially if I wanted to emphasize the animation or something similar, and that should play within the tool. I have ...

  18. : bad expression: Invalid left-hand side in assignment

    It means you're terminating your expression in the middle of it, causing the string concatenation operators to be seen on the left-hand side of an expression (i.e. the " + 5; + bitthe semi-colon terminates the current expression, which starts a new expression with the string concatenation operator). You're also missing some quotes and string ...

  19. How does pair programming on Code.org work?

    No - Pair programming on Code.org, in its current state, is designed to be used by students sharing one device and working together on one device. It is primarily designed for use in K-5 courses. We don't support live collaboration between students (and/or between teachers) on one single project or puzzle, but hope to add such support in the ...

  20. What does "bad invocation" typically mean in JS?

    console.log("Melbourne is great".substring(0, 12)); When JS sees "Melbourne is great"(0, 12), it tries to "invoke" (call) "Melbourne is great" assuming it to be a function, and then when it sees that it is not a function, it complains of "bad invocation". points. Submitted by Gaurang Tandon. about 10 years.

  21. What happens when I assign a course to a section? Can I ...

    What happens when a course is assigned to a section, or if I change the assignment? When you assign a course to a section of yours, this course will be the first thing students see upon signing in.

  22. What does "read only" mean as an error message?

    It means you are using a variable name that code.org is also using for their stuff too. I think this is a mistake made by a developer and have already opened a bug months ago. There is nothing to debug you just change the variable name you are using. For example name and location cannot be used by students.