Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
Display properties of an object based on value using express

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 class="image" 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.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

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 class="image" src="<%= fido.image %>" alt="<%= fido.name %>" />
    </a>
  <% } %>
<% }) %>
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda