Consider (and, more importantly, observe in your debugging) what this produces:
if(${nasaItem.media_type} === "image")
If you're expecting the value of nasaItem.media_type to ever be the string "image" then what you have is:
if(image === "image")
Unless you have a variable called image, this will produce an error. If you're expecting the value to be a string, wrap it in quotes:
if("${nasaItem.media_type}" === "image")
Edit: Once that's corrected, the second problem is that this doesn't make sense:
if("image" === "image"){
<img src="some_url_value" alt="Nasa Image of the Day" class="w-100 h-60 shadow" >
}
You can't just write HTML directly in the JavaScript code and expect that code to know what to do with it. Where in the DOM do you want to put that HTML code? For example, you're adding HTML to the DOM already with this operation:
document.querySelector("#nasaInfo1").insertAdjacentHTML("beforeend", "SOME HTML CODE");
This inserts the HTML in relation to the matched #nasaInfo1 element. That's how you'd add HTML to the DOM from JavaScript. So in the new JavaScript code you're adding... That's how you'd add HTML to the DOM.
Unless... What you actually meant was to invoke that JavaScript logic now as part of building the template literal. (Which is probably what you want, since dynamically adding JavaScript to the page is pretty strange and has a high potential for bugs.) In that case the logic needs to be in code, not part of the template literal string. Something like this:
`<section class="container my-5">
<div class="row g-3">
<div class="col-lg-6">
${
nasaItem.media_type === "image" ?
`<img src="${nasaItem.url}" alt="Nasa Image of the Day" class="w-100 h-60 shadow">` :
nasaItem.media_type === "video" ?
`<iframe src="${nasaItem.url}" frameborder="0"></iframe>` :
''
}
</div>
</div>
</section>`
So within the overall ${} of the larger template literal there is essentially an inline conditional (chaining some ternary conditional operators) to produce a value. That value is conditionally one of a couple other template literals, depending on the value of nasaItem.media_type.
This overall template literal should resolve to something like:
<section class="container my-5">
<div class="row g-3">
<div class="col-lg-6">
<img src="SOME_URL_VALUE" alt="Nasa Image of the Day" class="w-100 h-60 shadow">
</div>
</div>
</section>
You can nest the logic any way you like. But the logic needs to be part of the executing code, not part of a string. If it's part of the string then it will be added to the page like the rest of the string.
If the large template literal with inline conditions that add more template literals is getting unwiedly, you can always break it apart into multiple operations. For example:
let html = `
<section class="container my-5">
<div class="row g-3">
<div class="col-lg-6">`;
if (nasaItem.media_type === "image") {
html += `<img src="${nasaItem.url}" alt="Nasa Image of the Day" class="w-100 h-60 shadow">`;
} else if (nasaItem.media_type === "video") {
html += `<iframe src="${nasaItem.url}" frameborder="0"></iframe>`;
}
html += `
</div>
</div>
</section>`;
document.querySelector("#nasaInfo1").insertAdjacentHTML("beforeend", html);
I personally prefer the former. But there are a variety of ways one can organize one's code, including refactoring out small parts into their own aptly named functions to make the code more readable.
Any way you look at it, all you're doing is building a string. Don't over-complicate it by trying to put more code within that string and expecting it to execute. Just piece together the string however you need to.