# JavaScript Algorithm: Shopping List

Mar 19 · 2 min read

For today’s algorithm, we are not going to write a function but instead, we are going to learn basic JavaScript fundamentals, mainly the use of math operators.

For this algorithm, you are in charge of ordering food and you plan on ordering a lot of food. The food you’ll buy are:

`4 sandwiches6 salads5 wraps10 French fries`

The cost of each item per category is:

`sandwich - \$8.00salad - \$7.00wrap - \$6.50french fries - \$1.20`

The goal of this function is to output the total cost of your order.

We start out by creating four variables of each of the food categories. The cost times the quantity of each food item is assigned to the variables.

`const sandwiches = 4 * 8.00;const salads = 6 * 7.00;const wraps = 5 * 6.50;const frenchFries = 10 * 1.20;`

Next, we add up all the food items and assign it to a variable called `totalPrice`.

`let totalPrice = sandwiches + salads + wraps + frenchFries;`

The function will output the total which is `118.5`. That’s it. Hopefully, you understand what’s going on and how we got to this total.

Written by

## More From Medium

#### More from JavaScript in Plain English

Mar 30 · 7 min read

### 32 funny Code Comments that people actually wrote

Mar 3 · 9 min read

### The Top 6 JavaScript frameworks for 2020

Mar 20 · 5 min read

#### 521

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just \$5/month. Upgrade