Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more fields: age and isAlive #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 45 additions & 15 deletions data/data.json
Original file line number Diff line number Diff line change
@@ -1,62 +1,92 @@
[
{
"quote": "The greatest glory in living lies not in never falling, but in rising every time we fall.",
"author": "Nelson Mandela"
"author": "Nelson Mandela",
"isAlive": false,
"age": 95
},
{
"quote": "The way to get started is to quit talking and begin doing.",
"author": "Walt Disney"
"author": "Walt Disney",
"isAlive": false,
"age": 65
},
{
"quote": "Your time is limited, so don't waste it living someone else's life. Don't be trapped by dogma – which is living with the results of other people's thinking.",
"author": "Steve Jobs"
"author": "Steve Jobs",
"isAlive": false,
"age": 56
},
{
"quote": "If you set your goals ridiculously high and it's a failure, you will fail above everyone else's success.",
"author": "James Cameron"
"author": "James Cameron",
"isAlive": true,
"age": 68
},
{
"quote": "Life is what happens when you're busy making other plans.",
"author": "John Lennon"
"author": "John Lennon",
"isAlive": false,
"age": 40
},
{
"quote": "Tell me and I forget. Teach me and I remember. Involve me and I learn.",
"author": "Benjamin Franklin"
"author": "Benjamin Franklin",
"isAlive": false,
"age": 84
},
{
"quote": "It is during our darkest moments that we must focus to see the light.",
"author": "Aristotle"
"author": "Aristotle",
"isAlive": false,
"age": 61
},
{
"quote": "Whoever is happy will make others happy too.",
"author": "Anne Frank"
"author": "Anne Frank",
"isAlive": false,
"age": 15
},
{
"quote": "Do not go where the path may lead, go instead where there is no path and leave a trail.",
"author": "Ralph Waldo Emerson"
"author": "Ralph Waldo Emerson",
"isAlive": false,
"age": 78
},
{
"quote": "Life is really simple, but we insist on making it complicated.",
"author": "Confucius"
"author": "Confucius",
"isAlive": false,
"age": 71
},
{
"quote": "Imagination is more important than knowledge.",
"author": "Albert Einstein"
"author": "Albert Einstein",
"isAlive": false,
"age": 76
},
{
"quote": "Hold fast to dreams, for if dreams die, life is a broken winged bird that cannot fly.",
"author": "Langston Hughes"
"author": "Langston Hughes",
"isAlive": false,
"age": 66
},
{
"quote": "The future belongs to those who believe in the beauty of their dreams.",
"author": "Eleanor Roosevelt"
"author": "Eleanor Roosevelt",
"isAlive": false,
"age": 78
},
{
"quote": "Go confidently in the direction of your dreams. Live the life you have imagined.",
"author": "Henry David Thoreau"
"author": "Henry David Thoreau",
"isAlive": false,
"age": 44
},
{
"quote": "You cannot depend on your eyes when your imagination is out of focus.",
"author": "Mark Twain"
"author": "Mark Twain",
"isAlive": false,
"age": 74
}
]
16 changes: 12 additions & 4 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import getQuote, { getRandomQuote, getQuoteArrayLength, getQuoteByIndex } from "../lib/index.js";

const { quote, author } = getQuote();
const randomQuote = getRandomQuote();
const totalQuoteCount = getQuoteArrayLength();
const { quote: quoteWithoutAuthor } = getQuote({ author: false });
const { quote: quoteByIndex, author: authorByIndex } = getQuoteByIndex(10);
const { quote: quoteByIndex, author: authorByIndex, isAlive, age } = getQuoteByIndex(10);

console.log(`Here's a quote by "${author}": "${quote}"\n`);

console.log(`This is a random quote "${getRandomQuote()}"\n`);
console.log(`This is a random quote "${randomQuote}"\n`);

console.log(`Here is the quote object without the author "${quoteWithoutAuthor}"\n`);

console.log(`How many quotes are there? -> ${getQuoteArrayLength()}\n`);
console.log(`How many quotes are there? -> ${totalQuoteCount}\n`);

console.log(`"${quoteByIndex}" \nby "${authorByIndex}"\nThis is the one I want.`);
console.log(`"${quoteByIndex}" \nby "${authorByIndex}"\nThis is the one I want.\n`);

if (isAlive) {
console.log(`${authorByIndex} is alive and well`);
} else {
console.log(`${authorByIndex} was ${age} years old. He has passed away.`);
}