mbas
July 1, 2024, 4:46pm
1
Tell us what’s happening:
I am not why it keeps saying the same thing over and over again I have not changed my first line and I have followed the instructions
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
function addEntry() {
const targetInputContainer = document.querySelector(`#${entryDropdown.value} .input-container`);
const entryNumber = targetInputContainer.querySelectorAll('input[type="text"]').length;
const HTMLString = `
<label for="${entryDropdown.value}-${entryNumber}-name">Entry ${entryNumber} Name</label>
<input type="text" id="${entryDropdown.value}-${entryNumber}-name" placeholder="Name" />`;
<label for="${entryDropdown.value}-${entryNumber}-calories."> Entry ${entryNumber} Calories</label>
}
// 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/126.0.0.0 Safari/537.36
Challenge Information:
Learn Form Validation by Building a Calorie Counter - Step 49
you placed the label --outside-- the HTMLString literal. You needed to place it inside it (at the end)
1 Like
mbas
July 2, 2024, 1:43pm
3
const calorieCounter = document.getElementById('calorie-counter');
const budgetNumberInput = document.getElementById('budget');
const entryDropdown = document.getElementById('entry-dropdown');
const addEntryButton = document.getElementById('add-entry');
const clearButton = document.getElementById('clear');
const output = document.getElementById('output');
let isError = false;
function cleanInputString(str) {
const regex = /[+-\s]/g;
return str.replace(regex, '');
}
function isInvalidInput(str) {
const regex = /\d+e\d+/i;
return str.match(regex);
}
function addEntry() {
const targetInputContainer = document.querySelector(`#${entryDropdown.value} .input-container`);
const entryNumber = targetInputContainer.querySelectorAll('input[type="text"]').length;
const HTMLString = `
<label for="${entryDropdown.value}-${entryNumber}-name">Entry ${entryNumber} Name</label>
<input type="text" id="${entryDropdown.value}-${entryNumber}-name" placeholder="Name" />`;
<label for="${entryDropdown.value}-${entryNumber}-calories."> Entry ${entryNumber} Calories</label>
}
it is still not working
hi there,
the label is still not inside the string literal.
A string literal starts with a backtick ` and ends with a backtick.
So where is the last backtick for the HTMLString located?
Is it before or after the label text you made?
you want the backtick to surround all the text including the label
mbas
July 2, 2024, 2:18pm
7
function addEntry() {
const targetInputContainer = document.querySelector(`#${entryDropdown.value} .input-container`);
const entryNumber = targetInputContainer.querySelectorAll('input[type="text"]').length;
const HTMLString = `<label for="${entryDropdown.value}-${entryNumber}-name">Entry ${entryNumber} Name</label>
<input type="text" id="${entryDropdown.value}-${entryNumber}-name" placeholder="Name" />`;
<label for="${entryDropdown.value}-${entryNumber}-calories."> Entry ${entryNumber} Calories</label>`
`
}
like this?
ILM
July 2, 2024, 2:20pm
8
you need to add the label before the closing backtick, not add more backticks
mbas:
placeholder=“Name” />`;
this is the current end of the HTMLString. Do you see that?
So your new code must go after the input element and before the backtick
mbas
July 2, 2024, 6:38pm
10
function addEntry() {
const targetInputContainer = document.querySelector(`#${entryDropdown.value} .input-container`);
const entryNumber = targetInputContainer.querySelectorAll('input[type="text"]').length;
const HTMLString = `
<label for="${entryDropdown.value}-${entryNumber}-name">Entry ${entryNumber} Name</label>
<input type="text" id="${entryDropdown.value}-${entryNumber}-name" placeholder="Name" />`;
<label for="${entryDropdown.value}-${entryNumber}-calories."> Entry ${entryNumber} Calories</label>
}
do u mean like this
mbas:
`;
Move those two things, (a template literals string and a semicolon) after
mbas:
Calories</label>
After the above label closing tag.
mbas
July 2, 2024, 6:45pm
12
unction addEntry() {
const targetInputContainer = document.querySelector(`#${entryDropdown.value} .input-container`);
const entryNumber = targetInputContainer.querySelectorAll('input[type="text"]').length;
const HTMLString = `
<label for="${entryDropdown.value}-${entryNumber}-name">Entry ${entryNumber} Name</label>
<input type="text" id="${entryDropdown.value}-${entryNumber}-name" placeholder="Name" />;
<label for="${entryDropdown.value}-${entryNumber}-calories."> Entry ${entryNumber} Calories</label> `;
}
mbas:
/>;
Remove that from here In above line. Leave it after last line
mbas
July 2, 2024, 6:49pm
14
function addEntry() {
const targetInputContainer = document.querySelector(`#${entryDropdown.value} .input-container`);
const entryNumber = targetInputContainer.querySelectorAll('input[type="text"]').length;
const HTMLString = `
<label for="${entryDropdown.value}-${entryNumber}-name">Entry ${entryNumber} Name</label>
<input type="text" id="${entryDropdown.value}-${entryNumber}-name" placeholder="Name"
<label for="${entryDropdown.value}-${entryNumber}-calories."> Entry ${entryNumber} Calories</label> `;
}
is this it
You also removed input closing angular bracket.
You also have a .
in your for
attribute value and a space in your label text that should not be there.
I would suggest you copy your label element and reset.
Now create a new empty line inside the template string and paste the label back in.
Then remove the .
and the extra space from the label.
1 Like
mbas
July 2, 2024, 7:12pm
17
function addEntry() {
const targetInputContainer = document.querySelector(`#${entryDropdown.value} .input-container`);
const entryNumber = targetInputContainer.querySelectorAll('input[type="text"]').length;
const HTMLString = `
<label for="${entryDropdown.value}-${entryNumber}-name">Entry ${entryNumber} Name</label>
<input type="text" id="${entryDropdown.value}-${entryNumber}-name" placeholder="Name"
<label for="${entryDropdown.value}-${entryNumber}-calories"> Entry ${entryNumber} Calories</label> `;
}
Input element is not closed.
Remove space before Entry text.
mbas
July 2, 2024, 7:23pm
19
unction addEntry() {
const targetInputContainer = document.querySelector(`#${entryDropdown.value} .input-container`);
const entryNumber = targetInputContainer.querySelectorAll('input[type="text"]').length;
const HTMLString = `
<label for="${entryDropdown.value}-${entryNumber}-name">Entry ${entryNumber} Name</label>
<input type="text" id="${entryDropdown.value}-${entryNumber}-name" placeholder="Name">
<label for="${entryDropdown.value}-${entryNumber}-calories">Entry ${entryNumber} Calories</label> `;
}
That is why I said to reset. You are changing stuff you shouldn’t.
function addEntry() {
const targetInputContainer = document.querySelector(`#${entryDropdown.value} .input-container`);
const entryNumber = targetInputContainer.querySelectorAll('input[type="text"]').length;
const HTMLString = `
<label for="${entryDropdown.value}-${entryNumber}-name">Entry ${entryNumber} Name</label>
<input type="text" id="${entryDropdown.value}-${entryNumber}-name" placeholder="Name" />
// add the label here, do not change anything else in the template string
`;
}
1 Like