Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created July 13, 2020 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/553eabbb0e855aa97684d7ae382ec46b to your computer and use it in GitHub Desktop.
Save codecademydev/553eabbb0e855aa97684d7ae382ec46b to your computer and use it in GitHub Desktop.
Codecademy export
const quotes = [
{
quote: 'We build our computer (systems) the way we build our cities: over time, without a plan, on top of ruins.',
person: 'Ellen Ullman'
},
{
quote: 'The best thing about a boolean is even if you are wrong, you are only off by a bit.',
person: 'Anonymous'
},
{
quote: `If it's a good idea, go ahead and do it. It's much easier to apologize than it is to get permission.`,
person: 'Grace Hopper'
},
{
quote: 'The city’s central computer told you? R2D2, you know better than to trust a strange computer!',
person: 'C-3PO'
},
{
quote: 'I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone.',
person: 'Bjarne Stroustrup'
},
{
quote: 'Understand well as I may, my comprehension can only be an infinitesimal fraction of all I want to understand.',
person: 'Ada Lovelace'
},
{
quote: 'Java is to JavaScript as ham is to hamster.',
person: 'Jeremy Keith'
},
{
quote: `The most dangerous phrase in the language is, "We've always done it this way."`,
person: 'Grace Hopper'
},
{
quote: 'As soon as we started programming, we found to our surprise that it wasn’t as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.',
person: 'Maurice Wilkes'
},
{
quote: 'Learning to write programs stretches your mind, and helps you think better, creates a way of thinking about things that I think is helpful in all domains.',
person: 'Bill Gates'
},
{
quote: 'What one programmer can do in one month, two programmers can do in two months.',
person: 'Fred Brooks'
},
{
quote: 'The Internet? Is that thing still around?',
person: 'Homer Simpson'
},
{
quote: 'If you tell me precisely what it is a machine cannot do, then I can always make a machine which will do just that.',
person: 'Jon von Neumann'
},
];
module.exports = {
quotes
};
const express = require('express');
const morgan = require('morgan');
const app = express();
const { quotes } = require('./data');
const { getRandomElement } = require('./utils');
const PORT = process.env.PORT || 4001;
app.use(express.static('public'));
app.get('/api/quotes/random', function(req, res, next) {
let retobj = {};
const tmp = getRandomElement(quotes);
retobj = { quote: tmp}
res.send(retobj);
});
app.get('/api/quotes', function(req, res, next) {
let author = req.query.person;
let retobj = {};
if (author)
retobj = quotes.filter(element => element.person ===author);
else
retobj = quotes;
res.send({ quotes: retobj});
});
app.post('/api/quotes', function(req, res, next) {
let quote = req.query.quote;
let person = req.query.person;
if ( quote && person ) {
let retobj = {
quote: quote,
person: person
};
quotes.push(retobj);
res.send({ quote: retobj});
}
else
res.status(400).send();
});
app.listen(PORT, function () {
console.log('Example app listening on port 3000!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment