Skip to content

Instantly share code, notes, and snippets.

@giannispan
Created July 14, 2016 05:20
Show Gist options
  • Save giannispan/6109f24317bfa50af4a9a38c398bbec2 to your computer and use it in GitHub Desktop.
Save giannispan/6109f24317bfa50af4a9a38c398bbec2 to your computer and use it in GitHub Desktop.
Simple Quote Machine
.form-control {
height: 50px;
}
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Get your daily quote!</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
</head>
<body>
<div class="container">
<div class="row row-content">
<div class="col-xs-12">
<h3>Random Quote Machine</h3>
</div>
<div class="col-xs-12 col-sm-9">
<form class="form-horizontal">
<div class="form-group">
<div class="checkbox col-sm-10">
<p>Click on the "Get Quote" button to display a random quote</p>
<p>You can also share the quote by clicking the "Tweeter" button</p>
</div>
</div>
<div class="form-group">
<label for="feedback" class="col-sm-2 control-label">Your Quote</label>
<div class="col-sm-10 ">
<div class="form-control" id="quoteContainer"></div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button id="quoteButton" class="btn btn-success">Get Quote</button>
<a id="myTwitter" class="btn btn-info" href="#" target="_blank"><i class="fa fa-twitter"></i> Tweeter</a>
</div>
</div>
</form>
</div>
</div>
</div>
</body>
$(document).ready(function(){
var Quotation=new Array()
Quotation[0] = "Be yourself; everyone else is already taken - Oscar Wilde";
Quotation[1] = "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. - Albert Einstein";
Quotation[2] = "So many books, so little time. - Frank Zappa";
Quotation[3] = "Be the change that you wish to see in the world. - Mahatma Gandhi";
Quotation[4] = "If you tell the truth, you don't have to remember anything. - Mark Twain";
Quotation[5] = "Without music, life would be a mistake. - Friedrich Nietzsche";
Quotation[6] = "Life is what happens to you while you're busy making other plans. - Allen Saunders";
Quotation[7] = "I have not failed. I've just found 10,000 ways that won't work. - Thomas A. Edison";
Quotation[8] = "It is never too late to be what you might have been. - George Eliot";
Quotation[9] = "Everything you can imagine is real. - Pablo Picasso";
$('#quoteButton').click(function(evt){
evt.preventDefault();
var Q = Quotation.length;
var whichQuotation=Math.round(Math.random()*(Q-1));
var quoteContainer = $('#quoteContainer');
var tLink = document.getElementById('myTwitter');
quoteContainer.html('');
quoteContainer.append(Quotation[whichQuotation]);
var tUrl = 'https://twitter.com/intent/tweet?text=' + Quotation[whichQuotation];
tLink.setAttribute('href', tUrl);
// console.log(tUrl);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment