# Random Quote Generator: Issues Putting a Function within a Function

**URL:** <https://forum.freecodecamp.org/t/random-quote-generator-issues-putting-a-function-within-a-function/67079>\
**Category:** General\
**Created:** [December 19, 2016, 2:20pm UTC](https://forum.freecodecamp.org/t/random-quote-generator-issues-putting-a-function-within-a-function/67079 "2016-12-19T14:20:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casinclair](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@casinclair](https://forum.freecodecamp.org/u/casinclair)\
**Post date:** [December 19, 2016, 2:20pm UTC](https://forum.freecodecamp.org/t/random-quote-generator-issues-putting-a-function-within-a-function/67079/1 "2016-12-19T14:20:50Z")

</div>

After a great deal of work, I’ve gotten my page to display a random Bible verse every time it is loaded. However, if I try wrapping the code in another function and calling it when the document is ready and/or on a button click, it doesn’t work at all. Can someone help? My codepen is here: [http://codepen.io/csinclair/pen/YpBXXB](http://codepen.io/csinclair/pen/YpBXXB)

---

<div class="post-metadata">

**Author:** ![timotheap](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/timotheap/32/26039_2.png) [@timotheap](https://forum.freecodecamp.org/u/timotheap)\
**Post date:** [December 19, 2016, 2:39pm UTC](https://forum.freecodecamp.org/t/random-quote-generator-issues-putting-a-function-within-a-function/67079/2 "2016-12-19T14:39:13Z")

</div>

I don’t see your code for the wrapping function or the button click - can you put it so we can see what’s wrong?

---

<div class="post-metadata">

**Author:** ![JavaTheNutt](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/javathenutt/32/163777_2.png) [@JavaTheNutt](https://forum.freecodecamp.org/u/JavaTheNutt)\
**Post date:** [December 19, 2016, 2:42pm UTC](https://forum.freecodecamp.org/t/random-quote-generator-issues-putting-a-function-within-a-function/67079/3 "2016-12-19T14:42:31Z")

</div>

I’m not really sure what you’re asking, but I [forked your pen](http://codepen.io/JavaTheNutt/pen/yVZKgx?editors=1010) and got it working wrapped in the `$(document).ready(function(){..})`

---

<div class="post-metadata">

**Author:** ![casinclair](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@casinclair](https://forum.freecodecamp.org/u/casinclair)\
**Post date:** [December 19, 2016, 3:08pm UTC](https://forum.freecodecamp.org/t/random-quote-generator-issues-putting-a-function-within-a-function/67079/4 "2016-12-19T15:08:02Z")

</div>

Okay, so it works now. Thank you! (I was trying to wrap the whole thing, reather than just the bit with the AJAX.)

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [January 16, 2021, 6:10am UTC](https://forum.freecodecamp.org/t/random-quote-generator-issues-putting-a-function-within-a-function/67079/5 "2021-01-16T06:10:58Z")

</div>

Closed on January 16, 2021, 6:10am UTC


