Learn Form Validation by Building a Calorie Counter - Step 40

Tell us what’s happening:

Reading through the forum, the answer on this code might seem off, but could someone walk me through why this is not the beginning process of the answer

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

function addEntry() {
  targetId += "#";
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 40

Surely this has to be the solution:

function addEntry() {
  let targetId += "#" + entryDropdown.value;
}

targetId doesn’t exist yet, so you can’t use +=

But isnt that concatenation?

that’s the compound assignment, and it appends to the previous value of the variable, You are creating targetId there, so it doesn’t have a previous value. = is assignment, + is the concatenation operator.

So what is concatenation?

+ is the concatenation operator

It is "+ string +" right?

Do you mean how to use the + operator? You use it between two strings to obtain a string that is the two previous strings joined together
"a" + "b" makes "ab"

What is a concatenation?

this is concatenation, the concat operator creates a new string that is made of the two strings you use it with

Step 41 asks to concatenate , is this what it means?

You need to use the +, yes. You are already using concatenation.

But you can’t use the compound assignment as that is equal to let targetId = targetId + ... and targetId doesn’t exist yet, you are initializing it here

Ive put a question!