0
<% var percentage = (data.skills[i].rating / 10) * 100 %>
<div class="progress">
    <% var style = `style=width: percentage%` %>
    <div class="progress-bar color-1" role="progressbar" aria-valuenow="%= percentage %>"
                            aria-valuemin="0" aria-valuemax="10" <%= style %>>
         <span><%= percentage %>%</span>
    </div>
</div>

1 Answer 1

1

You need to use <%- for unescaped strings instead of <%= for style to work <%- style %>.

You forgot a < in front of %= here aria-valuenow="%= percentage %>

Also i'm not sure what you think this does style=width: percentage% since percentage% is just a string which will not be replaced by ejs engine.

So the correct code should look like bellow:

<% var percentage = (5 / 10) * 100 %>
<div class="progress">
    <% var style = `style="width: ${percentage}px"` %>
    <div class="progress-bar color-1" role="progressbar" aria-valuenow="<%= percentage %>"
                            aria-valuemin="0" aria-valuemax="10" <%- style %>>
         <span><%= percentage %>%</span>
    </div>
</div>

You can paste the code in this playground to see what the output is.

Sign up to request clarification or add additional context in comments.

1 Comment

such a small thing but it has huge implications , i can't believe i've missed the difference between = and - for the past 6 months ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.