A way to maintain if and else conditions

Viewed 55

hey guys i have a code currently looping some items. For the first "if" condition it gives an output when a condition is met and nothing when there is no statement matching the condition. But when i immediately insert the "else" condition it completely skips the first "if statement" and goes straight to the "else" statement even when the "if" condition is correct. Using ejs

<%Movies.find(element => {%>
  <%if(element.text === Details.title){%>
    <%console.log("found")%>
    <%return true%>
  <%} else {%>
    <%console.log("none")%>
    <%return true%>
  <%}%>
<%})%>

what do i do thanks...

1 Answers

Try this:

<% Movies.find(element => {
  console.log(element.text, Details.title)
  if(element.text === Details.title) {
    console.log("found")
    return true;
  } 
  console.log("none") 
  return true
}) %>

[EDIT]

You can simply do:

<% Movies.find(element => {
  console.log(element.text === Details.title ? "found" : "none")
  return element.text === Details.title
}) %>
Related