how to make three peanut butter and jelly sandwich in javascript

To make three peanut butter and jelly sandwiches in JavaScript, we can use variables to store the different ingredients, an array to represent the sandwich, and a loop to make the sandwiches.

// Define variables for ingredients
const bread = "bread";
const peanutButter = "peanut butter";
const jelly = "jelly";

// Define variable for number of sandwiches
const numSandwiches = 3;

// Define array to represent sandwich
const sandwich = [bread, peanutButter, jelly, bread];

// Loop through making sandwiches
for (let i = 1; i <= numSandwiches; i++) {
  console.log(`Making sandwich ${i}:`);
  console.log(`- Take two slices of ${bread}`);
  console.log(`- Spread ${peanutButter} on one slice`);
  console.log(`- Spread ${jelly} on the other slice`);
  console.log(`- Put the two slices together to make a sandwich`);
  console.log(`- Enjoy your ${sandwich.join(" ")} sandwich!\n`);
}
694 chars
21 lines

This code will output the following for each sandwich:

index.tsx
Making sandwich 1:
- Take two slices of bread
- Spread peanut butter on one slice
- Spread jelly on the other slice
- Put the two slices together to make a sandwich
- Enjoy your bread peanut butter jelly bread sandwich!

Making sandwich 2:
- Take two slices of bread
- Spread peanut butter on one slice
- Spread jelly on the other slice
- Put the two slices together to make a sandwich
- Enjoy your bread peanut butter jelly bread sandwich!

Making sandwich 3:
- Take two slices of bread
- Spread peanut butter on one slice
- Spread jelly on the other slice
- Put the two slices together to make a sandwich
- Enjoy your bread peanut butter jelly bread sandwich!
662 chars
21 lines

gistlibby LogSnag