I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
lineChecker doesn't tell me what it's checking, or what a "line" is, for that matter. I can guess it's a single line from some text based on the contents of the function, but...
This function doesn't do what it says
This function returns a formatted string based on the current line. It's producing output, not checking something. I'd expect a "check" function to return some meta information or a boolean regarding the passed data's validity.
As far as refactoring goes, there's no point in defining the document variable at all, and its name is misleading - it's a single HTML element as a string. "Document" is a word we associate with the DOM or, well, entire documents.
The last else if is redundant, it's the same as an else there.
I'd probably do this, but I'm not overjoyed about it:
javascript
formatLineAsHtmlFragment(line, isFirstLine) {
if (line === "") {
return "<br>";
}
if (isFirstLine) {
return `<h1>${line}</h1>`;
}
return `<p>${line}</p>`;
}
EDIT: why is my code not formatted as javascript when I did the backtick dance?
I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
It is, and it's exactly how I've done it in all my other posts where it works fine. I'm not sure what's wrong with this one. Anyway, people can imagine what it's like with colours :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I'd address two problems:
I don't know what this function does
lineChecker
doesn't tell me what it's checking, or what a "line" is, for that matter. I can guess it's a single line from some text based on the contents of the function, but...This function doesn't do what it says
This function returns a formatted string based on the current line. It's producing output, not checking something. I'd expect a "check" function to return some meta information or a boolean regarding the passed data's validity.
As far as refactoring goes, there's no point in defining the
document
variable at all, and its name is misleading - it's a single HTML element as a string. "Document" is a word we associate with the DOM or, well, entire documents.The last
else if
is redundant, it's the same as anelse
there.I'd probably do this, but I'm not overjoyed about it:
Triple-backtick
javascript
worked for me to get JS formatting.I just changed it to that and it still breaketh!
javascript
needs to be immediately after the 3 backticks, and needs to be followed by a newline.It is, and it's exactly how I've done it in all my other posts where it works fine. I'm not sure what's wrong with this one. Anyway, people can imagine what it's like with colours :)