Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

item or items based on sum variable #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div id="header">
<h1>The JSON Store</h1>
<div class="cart-info">
My Cart (<span class="cart-items">0</span> items)
My Cart contain (<span class="cart-item">0</span> <span class="cart-plural">item</span>)
</div>
</div>
<div id="main">
Expand Down
7 changes: 7 additions & 0 deletions javascripts/json_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,15 @@
$.each(this.session('cart') || {}, function(id, quantity) {
sum += quantity;
});

// function to decide whether use "items" or "item"
var plural = function(num) {
return ( num > 1 ) ? 'items' : 'item';
};

$('.cart-info')
.find('.cart-items').text(sum).end()
.find('.cart-plural').text( plural(sum) ).end()
.animate({paddingTop: '30px'})
.animate({paddingTop: '10px'});
});
Expand Down