Tell us what’s happening:
Hi everyone!
I’m working on the Markdown Previewer project. My code is working perfectly fine when I test it manually: headings, bold, and other elements are correctly converted in the preview.
However, the test runner keeps giving me this error:
“You should have a function named convertMarkdown that takes no parameters.”
I’ve double-checked everything:
The function name is exactly convertMarkdown.
It takes no parameters.
It correctly gets the value from #markdown-input
here is my code
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown to HTML Converter</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Markdown to HTML Converter</h1>
<div id="container">
<div class="container">
<h2>Markdown Input:</h2>
<textarea id="markdown-input" placeholder="Enter your markdown here..."></textarea>
</div>
<div class="container">
<h2>Raw HTML Output:</h2>
<div id="html-output"></div>
</div>
<div class="container">
<h2>HTML Preview:</h2>
<div id="preview"></div>
</div>
</div>
</body>
</html>
/* file: styles.css */
* {
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
padding: 20px;
}
#markdown-input {
width: 100%;
height: 100px;
}
#html-output, #preview {
height: 100px;
display: inline-block;
width: 100%;
border: 1px solid #ccc;
padding: 10px;
margin: auto;
white-space: pre-wrap;
background-color: #f9f9f9;
}
@media (min-width: 600px) {
#markdown-input, #html-output, #preview {
height: 200px;
margin: 0;
}
#container {
display: flex;
justify-content: space-evenly;
gap: 10px;
}
}
/* file: script.js */
const markDownInput=document.getElementById("markdown-input");
const htmlOuput=document.getElementById("html-output");
const preview=document.getElementById("preview");
const headingRegex=/^ *(#+) (.*)/gm;
const strongRegex=/(?:\*\*(.+)\*\*)|(?:__(.+)__)/gm;
const emphasisRegex=/(?:\*(.+)\*)|(?:_(.+)_)/gm;
const imageRegex=/!\[(.+)\]\((.+)\)/gm;
const linkRegex=/\[(.+)\]\((.+)\)/gm;
const quoteRegex=/^ *> (.+)/gm;
function convertMarkdown(){
let str=markDownInput.value;
str=str.replace(headingRegex,(match, capture1, capture2)=>`<h${capture1.length}>${capture2}</h${capture1.length}>`);
str=str.replace(strongRegex, (match, capture1, capture2)=>`<strong>${capture1||capture2}</strong>`);
str=str.replace(emphasisRegex, (match, capture1, capture2)=>`<em>${capture1||capture2}</em>`);
str=str.replace(imageRegex, (match, capture1, capture2)=>`<img alt=${capture1} src=${capture2}>`);
str=str.replace(linkRegex, (match, capture1, capture2)=>`<a href="${capture2}">${capture1}</a>`);
str=str.replace(quoteRegex, (match, capture1)=>`<blockquote>${capture1}</blockquote>`);
return str;
}
markDownInput.addEventListener("input",()=>{
htmlOuput.innerText=convertMarkdown();
preview.innerHTML=convertMarkdown();
})
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Challenge Information:
Build a Markdown to HTML Converter - Build a Markdown to HTML Converter