I am trying to concatenate a HTML string using + operator and I am using ternary operator to check the condition and use appropriate class name in the div element, however the ternary operator is giving me wrong output. I don't know what I am missing out here. Can anyone please explain?
My code looks like this :
fetch("./data/projects.json")
.then(res => {
return res.json();
})
.then(jsonResponse => {
var carouselItem = ''
jsonResponse.data.map((image, index) => {
carouselItem += '<div class="carousel-item ' + index === 0 ? 'a' : 'b' + '">'
})
console.log(carouselItem);
})
.catch(err => {
console.log(err);
})
I get the following output when I run this code
b">b">b">b">b">
I expect the output should be
<div class="carousel-item a"><div class="carousel-item b"><div class="carousel-item b"><div class="carousel-item b"><div class="carousel-item b">