Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. function doTrafficLights() {
  2. var activeLight = getActiveLight();
  3. // your code will replace this call
  4. // to `console.log()`
  5. if (activeLight === "red") {
  6. turnRed() ;
  7. } else if (activeLight === "yellow") {
  8. turnYellow() ;
  9. } else {
  10. turnGreen() ;
  11. }
  12.  
  13. }
  14.  
  15.  
  16. /* From here down, you are not expected to
  17. understand.... for now :)
  18.  
  19.  
  20. Nothing to see here!
  21.  
  22. */
  23.  
  24.  
  25. function turnOffLights() {
  26. $('.traffic-light').removeClass('yellow-on red-on green-on');
  27. }
  28.  
  29. function turnGreen() {
  30. turnOffLights();
  31. $('.green-light').addClass('green-on');
  32. }
  33.  
  34. function turnYellow() {
  35. turnOffLights();
  36. $('.yellow-light').addClass('yellow-on');
  37. }
  38.  
  39. function turnRed() {
  40. turnOffLights();
  41. $('.red-light').addClass('red-on');
  42. }
  43.  
  44. function getActiveLight() {
  45. return (['red', 'green', 'yellow'])[Math.floor(Math.random() * 3)];
  46. }
  47.  
  48. function handleClicks() {
  49. $('.js-control-lights').click(function() {
  50. doTrafficLights();
  51. });
  52. }
  53.  
  54. $(handleClicks);
  55.  
  56. /*-----------------------------------*/
  57.  
  58. function main() {
  59. try {
  60. doAllTheThings();
  61. }
  62. catch(e) {
  63. console.error(e);
  64. reportError(e);
  65. }
  66. }
  67.  
  68. function doAllTheThings() {
  69. throw {
  70. message: "Everything's ruined",
  71. name: "FatalException",
  72. toString: function(){return this.name + ": " + this.message;}
  73. }
  74. }
  75.  
  76. function reportError(e) {
  77. $('.js-error-report').text("Uh oh, something went wrong! Here's what we know: " + e.message);
  78. }
  79.  
  80.  
  81.  
  82. /* From here down, you are not expected to
  83. understand.... for now :)
  84.  
  85.  
  86. Nothing to see here!
  87.  
  88. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement