Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding up a total using jade template engine

Tags:

node.js

pug

I need to add up a total for a shopping basket but I dont know how to do this using jade

Here is how I thought I could implement it but it doesnt work, other ways I have tried just keep throwing errors.

Does anyone know how I would do this?

each item in bagItems
    - var total = total + item.realprice
p= total
like image 667
jamcoupe Avatar asked Jun 20 '26 01:06

jamcoupe


1 Answers

This should be pretty easy to do using the reduce method on your array.

p= bagItems.reduce(function(total, item) { return total + item.realprice; }, 0)
like image 55
Prestaul Avatar answered Jun 23 '26 10:06

Prestaul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!