Advertisement
Guest User

Untitled

a guest
May 29th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. You have been given a very simple HTML file.It has the following HTML elements in
  2.  
  3. its dom:
  4.  
  5. ● A button with id #getItemsButton
  6.  
  7. ● A span with id #loadingIndicator
  8.  
  9. ● A span with id #error
  10.  
  11. ● A div with id #results
  12.  
  13. There is also a JavaScript function defined: getDataFromBackend()​, which returns
  14.  
  15. a Promise.
  16.  
  17. The Promise returned by that function simulates a WebServer request (it’s not one
  18.  
  19. really). It will take some time to finish, and it will either return a response,
  20.  
  21. or fail:
  22.  
  23. ● When succesful, it will return a JavaScript object similar to the
  24.  
  25. following: {status: 200, items: []}
  26.  
  27. ○ The items​list will contain other objects of the following structure:
  28.  
  29. {name: ‘Example Name’, price: 15.0}
  30.  
  31. ● When failed, it will return a JavaScript object similar to the following:
  32.  
  33. {status: 403, message: ‘Permission Denied’}
  34.  
  35. Your task is to write code that does the following:
  36.  
  37. ● When the #getItemsButton ​gets clicked, getDataFromBackend()​is called.
  38.  
  39. ○ Until the Promise returned by getDataFromBackend()​is finished, the
  40.  
  41. button should be disabled
  42.  
  43. ○ Until the Promise is finished, #loadingIndicator​should contain the
  44.  
  45. text Loading...
  46.  
  47. If the Promise is rejected, please render the error message inside
  48.  
  49. #error
  50.  
  51. ○ If the Promise is resolved succesfully, please render the number of
  52.  
  53. items and a list of their names in prices inside #results​. The way
  54.  
  55. the results are rendered doesn’t really matter.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement