Last active
March 26, 2021 16:03
-
-
Save stoneboyindc/24f5642e90b689462987192be6df5223 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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