So I have a button that is supposed to make a variable "quote" from running a function. Then us jQuery to display the quote on the page, but whenever I try and assign the variable the jQuery function just stops right there and nothing happens. I have no clue whats getting caught up. Here's the button code and javascript.Thanks a lot!
<button class="btn btn-primary" id="quoteBtn">new quote</button>
var quote = quote();
function quote() {
var num = randomRange(1, 3);
switch (num) {
case 1:
return ["hat.", "- hatboy"];
case 2:
return ["shoes.", "- shoeboy"];
case 3:
return ["belt.", "- beltboy"];
}
}
function randomRange(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
$(document).ready(function() {
$("#quoteBtn").on("click", function() {
var quote = quote();
$("h2").html("<i class=\"fa fa-quote-left fa-lg\"></i>" + " " + quote[0]);
$("#author").html(quote[1]);
});
$("h2").html("<i class=\"fa fa-quote-left fa-lg\"></i>" + " " + quote[0]);
$("#author").html(quote[1]);
});
var quoteshould have a different name. I think it might overwrite yourfunction quote.