Last active
March 20, 2020 04:07
-
-
Save kluu1/af24d19a465128555ed35395ccbd419e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const shoppingCart = ['desktop', 'keyboard', 'speakers', 'mouse']; | |
| const addToCart = (cart, item) => { | |
| // checks if item does not exist in cart | |
| if (cart.indexOf(item) === -1) { | |
| console.log(`${item} has been added to the shopping cart`); | |
| return cart.push(item); | |
| } | |
| return console.log(`${item} is already in the shopping cart`); | |
| } | |
| addToCart(shoppingCart, 'mouse'); // mouse is already in the shopping cart | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment