Skip to content

Instantly share code, notes, and snippets.

@stoneboyindc
Last active March 26, 2021 16:03
Show Gist options
  • Save stoneboyindc/24f5642e90b689462987192be6df5223 to your computer and use it in GitHub Desktop.
Save stoneboyindc/24f5642e90b689462987192be6df5223 to your computer and use it in GitHub Desktop.
function listAllItems(products) {
if(products.length === 0){
return `There are no items for sale.`;
}
if(products.length === 1){
return `There is 1 item for sale: ${products[0].name}.`;
}
if(products.length === 2){
return `There are ${products.length} items for sale: ${products[0].name} and ${products[1].name}.`;
}
let str = [];
for(let i = 0; i < products.length; i++){
str.push(products[i].name);
} //end of loop
return `There are ${products.length} items for sale: ${str.join(', ')}.`;
} // end of function
module.exports = {
listAllItems,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment