Here's an example code snippet that creates three identical peanut butter and jelly sandwiches using arrays, loops, functions and strings in JavaScript:
index.tsx667 chars23 lines
This code defines the ingredients of a PB&J sandwich as constants, and then defines a function named makeSandwich()
for creating a sandwich. The function returns a string containing the ingredients of a sandwich, in the order they should appear between two slices of bread.
We then use a for
loop to call the makeSandwich()
function three times, and log the resulting sandwiches to the console.
gistlibby LogSnag