Reputation: 19
I want to add 2 numbers which is coming from the back end. I am trying to add
using <%=num1%> + <%=num2%>
but its printing num1num2 instead of num1+num2.
What I am doing wrong and what is alternative solution?
Upvotes: 0
Views: 2607
Reputation: 993
pass numbers to template from your controller.
res.render('index', { result: {n1:1,n2:2} });
and then in ejs template just like javascript
<%= n1+ n2 %>
Upvotes: 0
Reputation: 1782
This is done by
<%= num1 + num2 %>
What you are doing is only displaying the elements because when you have '<%=' this means to display this item. Another way to do this can be.
// Add the numbers
<% var addedNumber = num1 + num2; %>
//Then display the added numbers
<%= addedNumber %>
Upvotes: 2