Hello fellow Campers,
There must be a stupid mistake in my code, but can’t find a solution to pass test 3 and 4.
Error is:
So it says AssertionError: #preview is not being updated as I type into #editor (should update on every keyup) : expected ‘t’ to equal ‘a’ (content of my textarea was **test**
before I launched the tests.
However, when I type raw text / markdown / html in the textarea, everything is rendered correctly in the preview box.
My code :
My code
HTML
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<div id = "markdownWrapper"></div>
Javascript
const markdownContentOnLoad =
"# a header (H1 size)\n \
## a sub header (H2 size)\n \
alink.com\n\n \
`inline code`\n\n \
```a code block```\n\n \
* a list item\n \
> a blockquote\n\n \
an image \n\n \
**and bolded text.**";
class MarkdownWrapper extends React.Component {
constructor(props) {
super(props);
this.state = {
rawMarkdown: markdownContentOnLoad,
resultHtmlFromMarkdown: marked(markdownContentOnLoad)
};
this.handleChange = this.handleChange.bind(this);
}
handleChange(event) {
this.setState({
rawMardown: event.target.value,
resultHtmlFromMarkdown: marked(event.target.value)
});
console.log(marked(event.target.value));
}
render() {
return (
<div style={{ textAlign: "center" }}>
<textarea id="editor" onChange={this.handleChange}>
{this.state.rawMarkdown}
</textarea><br />
<div id="preview" key={Math.random()} dangerouslySetInnerHTML={{ __html: this.state.resultHtmlFromMarkdown }}></div>
</div>
);
}
}
ReactDOM.render(
<MarkdownWrapper />,
document.getElementById("markdownWrapper")
);
Thanks for your time
Edit: actually, I’m passing test 3 depending on the original content in textarea before launching the test, but then it fails on test 4