-
-
Save codecademydev/e47a7f2c7bdc54811887780bcab5d3a7 to your computer and use it in GitHub Desktop.
Codecademy export
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 express = require('express'); | |
| const app = express(); | |
| const PORT = process.env.PORT || 4001; | |
| const puddingFlavors = ['chocolate', 'banana', 'butterscotch', 'pistachio']; | |
| const findPuddingIndex = (name) => { | |
| return puddingFlavors.indexOf(name); | |
| } | |
| const deletePuddingAtIndex = (index) => { | |
| puddingFlavors.splice(index, 1); | |
| } | |
| // Your code here! | |
| app.delete('/puddings/:flavor', (req, res, next) => { | |
| const isAvailable = findPuddingIndex(req.params.flavor); | |
| if(isAvailable !== -1) { | |
| deletePuddingAtIndex(isAvailable); | |
| res.status(204).send(); | |
| } else { | |
| res.status(404).send(); | |
| } | |
| }) | |
| app.listen(PORT, () => { | |
| console.log(`Server is listening on port ${PORT}`); | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment