I'm trying to display properties of an object based on value. So basically if they value of the property is equal to "film" the property should display. This is the code I have so far:
<% fidos.forEach(fido => { %>
<%=fido.renown === "Film" %>
<% }) %>
The browser returns:
true true false false false false false false
But I would like it to display the name and image for the 2 true ones. I believe I should try an if else statement but I'm not sure how to set it up. I've tried:
<% fidos.forEach(fido => { %>
<% if fido.renown === "Film" { %>
<%=fido.name%>
<a href="/fidofame/<%=fido._id; %>">
<<img src=<%=fido.image %> alt=<%=fido.name %>> -->
<</a>
<% } else %>
<% }) %>
This returns a SyntaxError to the browser. I'm sorry for this basic question. I've only been programing for like 2 months.
CodePudding user response:
You are missing parentheses on the if condition and quotation marks on src
and alt
. This should work:
<% fidos.forEach(fido => { %>
<% if (fido.renown === "Film") { %>
<%= fido.name %>
<a href="/fidofame/<%= fido._id %>">
<img src="<%= fido.image %>" alt="<%= fido.name %>" />
</a>
<% } %>
<% }) %>