Title: JavaScript Conditional Statement Not Working
Tags: javascript;math;conditional
Question: What's wrong with this JavaScript?
var numPackages == 0;
if (coffeeProducts <= 12) {
numPackages == 1;
} else if (coffeeProducts % 12 == 0) {
numPackages == coffeeProducts/12;
} else {
numPackages == (coffeeProducts/12) + 1;
Basically, it needs to calculate the number of boxes/packages necessary to ship an amount of items (12 per box). Is there a better way to do this, perhaps using round()?
Comment: The problem is that you're confusing assignments with conditionals.

Here is the accepted answer: All the others explained your mistake with the comparing operator == and the assigning operator =.
The shortest way to solve it would be
var numPackages = Math.ceil( coffeeProducts / 12 );

Here is another answer: Single equals (=) for assignment: x = 10
Double equals (==) for comparison: if (x == 10)
Triple equals for special cases where type is important as well as the value.
Change your two numPackages lines to a single equals and you're good to go :)

Here is another answer: Make each statement look like this:
if (coffeeProducts <= 12) {
numPackages = 1; // just "=", not "=="

Here is another answer: == is condition.
= is assignment.
The better way is to use Math.ceil() to round to next integer.
var numPackages = Math.ceil(coffeeProducts/12);
Comment for this answer: Gotcha! Thanks for the help. :)

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 4, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:01/05/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><math><conditional>', 'Title': 'JavaScript Conditional Statement Not Working', 'ViewCount': 271, 'id': 14177578, 'user_AboutMe': '', 'user_AccountId': 296107.0, 'user_DisplayName': 'Trent Scott', 'user_Reputation': 2008.0, 'user_Views': 144.0, 'user_id': 600873.0}}