The function is not defined, I want to get the jobtitle and show it in the ejs file without the hyphen and capitalize the first letter
When i remove the function the job title is shown
I tried to change the received jobtitle in the route
example – (software-engineer) to (Software Engineer)
router.get('/job/:jobTitle',(req,res) => {
const { jobTitle } = req.params;
res.render('job',{ jobTitle });
});
<p class="job-title"><%= formatJobTitle(jobTitle) %></p>
<script>
function formatJobTitle(jobTitle) {
const words = jobTitle.split('-');
const formattedTitle = words.map(word => {
return word.charAt(0).toUpperCase() + word.slice(1);
}).join(' ');
return formattedTitle;
}
</script>
router.get('/job/:jobTitle', (req, res) => {
const { jobTitle } = req.params;
const formattedJobTitle = formatJobTitle(jobTitle);
res.render('job', { jobTitle: formattedJobTitle });
});
function formatJobTitle(jobTitle) {
const words = jobTitle.split('-');
const formattedTitle = words.map(word => {
return word.charAt(0).toUpperCase() + word.slice(1);
}).join(' ');
return formattedTitle;
}