Ahmed
Ahmed

Reputation: 1359

How can I check if a variable is less then a certain number in ejs

I have the following code

<%if (locals.average > 4.5 && locals.average < 5){%>
              <div>test</div>
<%}%>

If i apply the following code the test div doesnot appear I think the problem is with less than 5 because if I use this only

<%if (locals.average > 4.5){%>
              <div>test</div>
<%}%>

It works fine. How can I use less than symbol in ejs

Upvotes: 1

Views: 758

Answers (1)

Dai
Dai

Reputation: 155428

I'm not familiar with ejs - but assuming your parser is tripping-up on < (e.g. thinking it's the start of a tag) then use the logical inverse of less-than (which is not-greater-than-or-equal-to):

<% if( locals.average > 4.5 && !( locals.average >= 5 ) ) { %>
              <div>test</div>
<% } %>

That said, the documentation for ejs suggests that your original code should work - as it's just a normal JavaScript expression. If you find out why it really didn't work you should post that as the answer and accept that answer instead of mine.

Upvotes: 1

Related Questions