JSFiddle - React, Tailwind, and code Playground
by ppanagi
HTML
<button id="myButton" type="button">Get a random number lower than:</button>
<input id="myNumberPicker" type="number" min="1" max="10000" value="50">
JavaScript
//(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 display the returned random numbers more elegantly than using an alert, you can modify the onComplete method, but it's not necessary
//We estimate this wouldn't take longer than 30 minutes or so, but don't be surprised if you finish it faster. Please _don't_ spend longer than an hour.
//You can use libraries...