Learn the Date Object by Building a Date Formatter - Step 14

Tell us what’s happening:

I think my syntax is correct. I see the date printed on preview screen.

Your code so far

currentDateParagraph.textContent = ${formattedDate};

WARNING

The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.

Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.

Your browser information:

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

Challenge Information:

Learn the Date Object by Building a Date Formatter - Step 14

Did you follow the very last instruction:
Also, make sure to remove your console.log(formattedDate); line.

Otherwise, what error are you seeing?

I deleted that line but it still shows this error:

You should use the textContent property to set the text content of currentDateParagraph to the value of the constant formattedDate .

What type of constant is “formattedDate”? (such as a number or an object?)
What kind of thing is currentDateParagraph.textContent expecting? Is it expecting an object, a number, or a string? If formattedDate is already a string, do we need to put it inside of another string?

const currentDateParagraph = document.getElementById(“current-date”);

currentDateParagraph is a

element extracted from html document.
textContent property can put new text or replace old text with new text.

Here is the provided example:

p id="example-paragraph">Example Text</p>
const exampleParagraph = document.getElementById("example-paragraph");
console.log(exampleParagraph.textContent); // "Example Text"
exampleParagraph.textContent = "New Text";
console.log(exampleParagraph.textContent); // "New Text"

I

I think you are running into a problem that isn’t a problem. Back to basics: .textContent is expecting a string. Whether this is hard coded with such as “This is a string” or ‘This is also a string’ or with a string literal.

The constant “formattedDate” is a string literal which is a string. So your code is feeding the .textContent a string literal that contains a variable that is already a string. That will work in reality (which is why the preview shows correctly), but doesn’t pass the module’s check because you don’t need another string literal. You just need to pass in the variable “formattedDate” because it is already a string.

2 Likes

I got it fixed. Thank you!

1 Like