I am doing a very simple version of random quote machine. I have fiddled and sweated and finally given up on using document.ready function. I can’t even manage to get an alert onclick to work from within document.ready.
What am I doing wrong? Here is my working random quote generator with all code sitting outside of the (greyed out) document.ready: https://codepen.io/m4sterbunny/live/aGKVNK
Here is the JS:
// Feed quote and author even with button not pressed so quote shows on first load;
$(function(){
feedStaticQuote();
});
// I am failing to run anything inside document.ready function
//$document.ready(function(){
// this is to test button onclick
/**$(".btn").on("click", function(){
showInnerMessage();
});
function showInnerMessage() {
alert("alert triggered with Jquery");
}
*/
$(".btn").on("click", function(){
feedStaticQuote();
});
function feedStaticQuote(){
var staticQuoteArr = [];
var staticQuoteAut = [];
staticQuoteArr = ["Beware of the man who works hard to learn something, learns it, and finds himself no wiser than before he is full of murderous resentment of people who are ignorant without having come by their ignorance the hard way.", "Man invented language to satisfy his deep need to complain.", "A bore is a man you deprives you of solitude without providing you with company."];
staticQuoteAut = ["Kehlog Albran", "Lily Tomlin", "Gian Vincenzo Gravina"];
//Math.random returns 0-1 hence *10. Then I need to limit to possible array length hence / arr.length
// Math floor removes decimal value
var randomStatic = Math.floor(Math.random()*10/staticQuoteAut.length);
var randomQuote = staticQuoteArr[randomStatic];
var randomAuth = staticQuoteAut[randomStatic];
// Feed quote and author even with button not pressed;
return ($('.quote').text("'" + randomQuote + "'") + $('.author').text(randomAuth));
}
//});
//});