please can you help me find where the problem is from
this is the code I have on my ejs file and this is where the problem is from
<% if(user.account.deposits.length){ %>
<% user.account.deposits.sort(sortFunction).map(history=>{ %>
<% var className = history.approved ? "text-success" : "text-warning" %>
<% status = history.approved ? "approved" : "pending" %>
<% return( %>
<tr>
<th scope="row"> <% history.sort %> </th>
<td class="<%= className %>"><%= status %></td>
<td><%= history.amount %><b> $</b></td>
<td> <%= history.date %></td>
</tr>
<% )}) %>
<% }else{ %>
<% return ( %>
<tr>
<th scope="row">#</th>
<td class="text-light" colspan="3"> You have no deposit history</td>
</tr>
<% ) } %>
with ejs-lint, i am getting
- Unexpected token (86:32) in views/profile/deposit.ejs "><%= status %></td *
error I am getting in the consolse
- SyntaxError: Unexpected token ';' in C:######\views\profile\deposit.ejs while compiling ejs * i have checked and can't find where the error is
CodePudding user response:
Well, when ejs parses your code it turns it into javascript code without the html stuff and this
<% return( %><tr>
results in
... return( ; __append("\n ...
and that ;
after (
causes the error. And since you don't need the return
at all you can remove it.
The bellow code should work
<% if(user.account.deposits.length){ %>
<% user.account.deposits.sort(sortFunction).map(history=>{ %>
<% var className = history.approved ? "text-success" : "text-warning" %>
<% status = history.approved ? "approved" : "pending" %>
<tr>
<th scope="row"> <% history.sort %> </th>
<td class="<%= className %>"><%= status %></td>
<td><%= history.amount %><b> $</b></td>
<td> <%= history.date %></td>
</tr>
<% }) %>
<% }else{ %>
<tr>
<th scope="row">#</th>
<td class="text-light" colspan="3"> You have no deposit history</td>
</tr>
<% } %>