YNAB
by ironicmuffin
HTML
<button id="myButton" type="button">Get a random number lower than:</button>
<input id="myNumberPicker" type="number" min="1" max="10000" value="50">
<ul id="results"></ul>
JavaScript
/* 6/19/2013
Hello YNAB!
Fun task. I think I got working per the requirements.
Planned to go native JS, but threw in jQuery to quickly slap the results into a list to visually validate the results. I'm sure it could be refactored in some slick fashion, but didn't want to spend more time than necessary. ;)
*/
//(This code was tested on the latest Chrome)
//
//Instructions:
//You're replacing an intern who had an unfinished task:
//----------
//We just bought a random number generating library with a single function:
//getRandomNumber(
// maximumNumber /*The maximum random number to return*/ ,
// callback /*callback signature: function callback(err, value)*/ ) {
//It's asynchronous, so there's a callback that will be called when the random number is ready.
//Make us a page that has a button that we can press to get a new random number
//We should be able to easily choose the maximum value for the random number
//If I hit the button multiple times, I should issue multiple requests for random numbers
//The library vendor said that sometimes there will be an error, so make sure it detects that too
//The vendor also told us it won't take longer than 5 seconds to issue the callback. If it does, you're never going to get a response.
//Since this is just a demo, I don't care how you display the numbers returned. Heck, you can just display an alert with the values returned.
//-----------
//So, the intern got to work, and the below is what he wrote
//
//Look for the YOUR CODE GOES IN THIS FUNCTION and fill it in so that clicking on the button
//results in the onComplete method being called with the appropriate "requestor" object passed in
//Notes:
//We're looking for simple, well written code that works when we click the button
//You don't have to try and impress us with full test suites or massive refactorings or anything like that
//We prefer closures instead of global variables to keep track of state (multiple requests, etc)
//If you'd rather...